简体   繁体   English

Zend 框架从 model class 调用 _partial

[英]Zend Framework calling _partial from a model class

I can call partial method from a view object.我可以从 object 的视图中调用部分方法。 However, I need to call it from a model class (which is standalone).但是,我需要从 model class (它是独立的)调用它。 I need to render a xhtml piece (with code) and parse the result and it happens inside a model class.我需要渲染一个 xhtml 片段(带有代码)并解析结果,它发生在 model class 内部。

Is it possible?可能吗?

yeah, but usually views shouldn't be generated by the models directly.是的,但通常视图不应该由模型直接生成。 Any interaction with the views should be done by the controllers.与视图的任何交互都应由控制器完成。

Here's a code snippet to use Zend_View as a standalone:这是一个单独使用 Zend_View 的代码片段:

    $view = new Zend_View;
    $view->setBasePath(APPLICATION_PATH . '/modules/blog/views/');

    $view->subject = $subject;

    $htmlMessage = $view->render('emails/template.phtml');

You should be able to access your view object, and subsequently partial view helper, in a model as follows:您应该能够在 model 中访问您的视图 object 以及随后的部分视图助手,如下所示:

$view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');
$view->partial(/*usual parameters here*/);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM