目前我发现我必须为不同的模块重复部分内容。
我想要一个案例目录来访问所有部分。
有没有人有这样做的好方法?
由于
答案 0 :(得分:8)
$this->partial('directoryOfPartials/partial.phtml', $model);
我认为你也可以使用带有三个参数的$ this-> partial。第二个参数是模块名称,第三个参数成为模型。
取自: http://framework.zend.com/manual/en/zend.view.helpers.html
示例#10渲染部分 其他模块有时是部分意志 存在于不同的模块中。如果你 知道模块的名称,你可以 将它作为第二个参数传递给 partial()或partialLoop(), 将$ model参数移动到第三个 位置。例如,如果有的话 寻呼机部分你希望使用那个 在'list'模块中,你可以抓住 它如下:
<?php echo $this->partial('pager.phtml', 'list', $pagerData) ?>
通过这种方式,您可以重复使用部分内容 专门为其他人创建的 模块。那就是说,它可能是一个 更好的做法是重复使用 共享视图脚本路径中的部分内容。
编辑 - 从控制器的操作范围内访问视图部分
$this->view->getHelper('partial')->partial('comments.phtml');
答案 1 :(得分:2)
非常感谢:)
但是,我如何通过控制器执行此操作?我有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-&gt; view-&gt; partial与在视图模板中使用$ this-&gt; partial相同,但我猜不是。想法?
通过VIA解决:
Bootstrap initView,添加:
$view->addScriptPath('../application/layouts/partials');
将我的部分移动到该目录。然后在我的控制器中我做:
$this->view->layout()->setLayout('ajax');
$this->view->form = $form;
$this->renderScript('login.phtml');
感谢#zftalks SmartSsa