具有部分基础的模块化 Zend 框架

发布于 2024-08-27 11:19:19 字数 89 浏览 3 评论 0原文

目前我发现我必须不断复制不同模块的部分内容。

我想要一个可供访问所有部分的案例目录。

有人有这样做的好方法吗?

谢谢

Currently I'm finding I have to keep duplicating partials for different modules.

I would like to have a case directory for all partials to be accessed.

Does anyone have a good way of doing this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

懵少女 2024-09-03 11:19:20
$this->partial('directoryOfPartials/partial.phtml', $model);

我认为您也可以将 $this->partial 与三个参数一起使用。第二个参数是模块名称,第三个参数成为模型。

摘自:
http://framework.zend.com/manual/en/zend.view .helpers.html

示例 #10 在中渲染部分
其他模块 有时会有部分意愿
存在于不同的模块中。如果你
知道模块的名称,就可以
将其作为第二个参数传递给
部分()或部分循环(),
将 $model 参数移至第三个
位置。例如,如果有一个
您希望使用的寻呼机部分是
在“列表”模块中,您可以抓取
如下:

partial('pager.phtml', 'list', $pagerData) ?>;

这样就可以复用partials了
专门为其他人创建的
模块。也就是说,这很可能是一个
更好的做法是可以重复使用
共享视图脚本路径中的部分。

编辑 - 从控制器的操作范围内访问视图部分

$this->view->getHelper('partial')->partial('comments.phtml');
$this->partial('directoryOfPartials/partial.phtml', $model);

I think you can also use $this->partial with three arguments. The second argument is a module name and the third argument becomes the model.

Taken From:
http://framework.zend.com/manual/en/zend.view.helpers.html

Example #10 Rendering Partials in
Other Modules Sometime a partial will
exist in a different module. If you
know the name of the module, you can
pass it as the second argument to
either partial() or partialLoop(),
moving the $model argument to third
position. For instance, if there's a
pager partial you wish to use that's
in the 'list' module, you could grab
it as follows:

<?php echo $this->partial('pager.phtml', 'list', $pagerData) ?>

In this way, you can re-use partials
created specifically for other
modules. That said, it's likely a
better practice to put re-usable
partials in shared view script paths.

EDIT - Accessing view partials from within a Controller's Action scope

$this->view->getHelper('partial')->partial('comments.phtml');
遗失的美好 2024-09-03 11:19:20

非常感谢:)

但是,我如何通过控制器执行此操作?我有 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 相同在视图模板内,但我想不是。有想法吗?

已解决:

Bootstrap initView,添加:

$view->addScriptPath('../application/layouts/partials');

将我的部分内容移至该目录。然后在我的控制器中我这样做:

$this->view->layout()->setLayout('ajax');
$this->view->form  = $form;
$this->renderScript('login.phtml');

感谢 #zftalks SmartSsa

Excellent thanks :)

However, how do I do this via the controller? I have fancybox and have set up the ajax layout:

$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);

The pop up window as required but with the following error:

Problem: Method "partial" does not exist and was not trapped in __call()

I kinda of assumed the $this->view->partial would be the same as using $this->partial inside the view template, but I guess not. Ideas?

SOLVED VIA:

Bootstrap initView, added:

$view->addScriptPath('../application/layouts/partials');

Moved my partials to that directory. Then in my controller I do:

$this->view->layout()->setLayout('ajax');
$this->view->form  = $form;
$this->renderScript('login.phtml');

Thanks goes out to #zftalks SmartSsa

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文