如果我从模型调用视图,如何将 Zend Layout 与 Zend View 一起使用?
基本上,我想从模型渲染视图和布局。 别问我为什么。
首先,这些视图按预期工作,我将它们加载到变量中以供稍后使用。 我也完全意识到我总是可以做部分脚本。 这似乎是一个有效的后备方案,但它只是没有解决问题。
我想做的是让布局自动工作,就像控制器和视图的情况一样。
现在我采用这样的方法:
// Class blablabla
$layout = new Zend_Layout();
$layout->enableLayout();
$layout->setView($view);
// Ugly url, I know, I'm experimenting and they work
$body = $layout->render('mailer/layout/mail');
$body .= $view->render('mailer/templates/' . $type . '.phtml');
问题是 $body 包含布局,并且仅包含实际视图。 有什么建议吗? 我究竟做错了什么?
Basically, I want to render a view and layout from a model. Don't ask me why.
First of all, the views work as intended and I'm loading them into a variable for my perverse use later on. I am also fully aware that I could always do partial scripts. It seems to be a valid fallback, but it just doesn't cut it.
What I want to do is to get the layout to work automatically just like in the case with controllers and views.
Right now I employ something like this:
// Class blablabla
$layout = new Zend_Layout();
$layout->enableLayout();
$layout->setView($view);
// Ugly url, I know, I'm experimenting and they work
$body = $layout->render('mailer/layout/mail');
$body .= $view->render('mailer/templates/' . $type . '.phtml');
The problem is that $body contains the layout and only then the actual view. Any advice? What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您的布局在某处包含默认的
$this->layout()->content
,您需要这样:来源:http://www.wowww.ch/2009/03 /16/zend-mail-avec-template-standardise-avec-zend-layout-et-zend-view/
Assuming that your layout contains the default
$this->layout()->content
somewhere, you'd want this:Source: http://www.wowww.ch/2009/03/16/zend-mail-avec-template-standardise-avec-zend-layout-et-zend-view/
我想我的第一个注释必须是你正在尝试使用锤子作为螺丝刀。 我确信您知道,在 MVC 模型中,视图是渲染,并且在逻辑上与模型不同(分离)。 我不确定你是否能找到一个满意的解决方案,因为你正在过河。
I think my first note would have to be that you're trying to use a hammer as a screwdriver. As I'm sure you know, in the MVC model the view is the rendering, and is logically distinct (separate) from the model. I'm not sure you're going to find a happy solution to this, since you're crossing the streams.