ZF2 use database table model in view helper

孤人 提交于 2019-12-06 12:08:10

create a view helper

namespace My\View\Helper;
use Zend\View\Helper\AbstractHelper;

class CounterHelper extends AbstractHelper
{
    protected $count;

    public function __invoke()
    {
       return $this->count;   
    }

    public function setTableCount($sm, $mytablemodel)
    {
        $this->count =  $sm->get($mytablemodel)->getCountedData();
        return $this->count;
    }
}

and inject view_helpers via factories

'view_helpers' => array(
    'factories' => array(
     'counter_helper' => function($sm) {
        $helper = new \My\View\Helper ;
            $helper->setTableCount($sm, 'mytablemodelthatalreadyregisteredinSM');

        return $helper;
     }
    )
),
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!