目前我发现我必须不断为不同的模块复制部分。
我想为所有要访问的部分提供一个案例目录。
有没有人有这样做的好方法?
谢谢
$this->partial('directoryOfPartials/partial.phtml', $model);
我认为您也可以将 $this->partial 与三个参数一起使用。第二个参数是模块名称,第三个参数成为模型。
取自:http : //framework.zend.com/manual/en/zend.view.helpers.html
Example #10 在其他模块中渲染局部 有时局部会存在于不同的模块中。如果您知道模块的名称,则可以将其作为第二个参数传递给 partial() 或 partialLoop(),将 $model 参数移至第三个位置。例如,如果您希望使用“列表”模块中的寻呼机部分,您可以按如下方式获取它:
<?php echo $this->partial('pager.phtml', 'list', $pagerData) ?>
通过这种方式,您可以重用专门为其他模块创建的部分。也就是说,将可重用的部分放在共享视图脚本路径中可能是一种更好的做法。
编辑 - 从控制器的操作范围内访问视图部分
$this->view->getHelper('partial')->partial('comments.phtml');
非常感谢:)
但是,如何通过控制器执行此操作?我有fancybox并设置了ajax布局:
$this->view->layout()->setLayout('ajax');
$errors = array('You have lost your rights to download this clip, you have downloaded it the maximum amount of times.');
$this->render($this->view->partial('partials/errors.phtml', 'default', array('errors' => $errors)), NULL, true);
根据需要弹出窗口,但出现以下错误:
Problem: Method "partial" does not exist and was not trapped in __call()
我有点假设 $this->view->partial 与在视图模板中使用 $this->partial 相同,但我猜不是。想法?
通过以下方式解决:
引导 initView,添加:
$view->addScriptPath('../application/layouts/partials');
将我的部分内容移至该目录。然后在我的控制器中我做:
$this->view->layout()->setLayout('ajax');
$this->view->form = $form;
$this->renderScript('login.phtml');
感谢#zftalks SmartSsa