在我的控制器中,我使用json模型进行" ajax动作"。在动作中,我有一个数据实体数组,我想用" partialLoop查看助手"
我使用下面列出的代码
public function addLookuptableAction(){
try{
//CUT
$repositoryModuloLookup = $this->em->getRepository('User\Entity\ModuloLookup');
$moduloLookUpEnAllArr = $repositoryModuloLookup->findAll();
$htmlModuleLookUp = $this->createHtmlModuleLookUp($moduloLookUpEnAllArr);
$o['s'] = 'success';
$o['i'] = "ok" . $out;
}catch(\Exception $e){
$newExceptionCode = new GetExceptionCode($this);
$o['s'] = 'error';
$o['i'] = $newExceptionCode->GetCode($e);;
}
return new JsonModel($o);
}
private function createHtmlModuleLookUp($moduloLookUpEnAllArr){
if(count($moduloLookUpEnAllArr) > 0){
$partialLoop = $this->getPartialLoop();
//$partialLoop->setView(new View() );
$partialLoop('modulo.lookuptbl.tbl.phtml',$moduloLookUpEnAllArr)->setObjectKey('object');
}
}
private function getPartialLoop(){
return new \Zend\View\Helper\PartialLoop();
}
但我收到以下错误代码
Fatal error: Call to a member function render() on a non-object in D:\www\httpdocs\test\vendor\zendframework\zendframework\library\Zend\View\Helper\Partial.php on line 61
错误很明显
有没有办法用vie helper获得我想要的东西?
答案 0 :(得分:0)
您可以从控制器serviceLocator
获取。首先你必须得到viewHelperManager
,一旦你得到它,你就可以找到partialLoop
:
$vhm = $this->getServiceLocator()->get( 'viewhelpermanager' );
$partialLoop = $vhm->get( 'partialloop' );
您可以通过viewHelperManager
:
'doctype' => 'Zend\View\Helper\Doctype', // overridden by a factory in ViewHelperManagerFactory
'basepath' => 'Zend\View\Helper\BasePath',
'url' => 'Zend\View\Helper\Url',
'cycle' => 'Zend\View\Helper\Cycle',
'declarevars' => 'Zend\View\Helper\DeclareVars',
'escapehtml' => 'Zend\View\Helper\EscapeHtml',
'escapehtmlattr' => 'Zend\View\Helper\EscapeHtmlAttr',
'escapejs' => 'Zend\View\Helper\EscapeJs',
'escapecss' => 'Zend\View\Helper\EscapeCss',
'escapeurl' => 'Zend\View\Helper\EscapeUrl',
'gravatar' => 'Zend\View\Helper\Gravatar',
'headlink' => 'Zend\View\Helper\HeadLink',
'headmeta' => 'Zend\View\Helper\HeadMeta',
'headscript' => 'Zend\View\Helper\HeadScript',
'headstyle' => 'Zend\View\Helper\HeadStyle',
'headtitle' => 'Zend\View\Helper\HeadTitle',
'htmlflash' => 'Zend\View\Helper\HtmlFlash',
'htmllist' => 'Zend\View\Helper\HtmlList',
'htmlobject' => 'Zend\View\Helper\HtmlObject',
'htmlpage' => 'Zend\View\Helper\HtmlPage',
'htmlquicktime' => 'Zend\View\Helper\HtmlQuicktime',
'inlinescript' => 'Zend\View\Helper\InlineScript',
'json' => 'Zend\View\Helper\Json',
'layout' => 'Zend\View\Helper\Layout',
'paginationcontrol' => 'Zend\View\Helper\PaginationControl',
'partialloop' => 'Zend\View\Helper\PartialLoop',
'partial' => 'Zend\View\Helper\Partial',
'placeholder' => 'Zend\View\Helper\Placeholder',
'renderchildmodel' => 'Zend\View\Helper\RenderChildModel',
'rendertoplaceholder' => 'Zend\View\Helper\RenderToPlaceholder',
'serverurl' => 'Zend\View\Helper\ServerUrl',
'viewmodel' => 'Zend\View\Helper\ViewModel',