访问模型/控制器中的视图 [英] Access views in Models/Controllers
本文介绍了访问模型/控制器中的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的 MyData.php 类:
class myData {
function render() {
$view = new Zend_View();
$view->str = 'This is string.';
echo $view->render('myview.phtml');
}
}
和一个 myview.phtml 文件:
<div id='someid'><?= $this->str ?></div>
在另一个视图中,我正在做这样的事情:
In another view I am doing something like this:
<?php
$obj = new myData ();
$obj->render(); // it should be <div id='someid'>This is string.</div>
?>
它给了我以下异常:
Message: no view script directory set; unable to determine location for view script
MyData.php 和 myview.phtml 在同一目录中.
MyData.php and myview.phtml are in same directory.
推荐答案
我是这样做的:
我将我的 myview.phtml 更改为 myview.php
<div id='someid'><?= $this->str ?></div>
在 myData 类渲染函数中:
In myData class render function:
class myData {
function render() {
$view = new Zend_View();
$view->setScriptPath( "/Directory/Path/For/myview/php/file" );
$view->str = 'This is string.';
echo $view->render('myview.php');
}
}
一切都如我所问的那样工作.我的代码中缺少 $view->setScriptPath($path);
.
And all things are working as I asked in question. I was missing $view->setScriptPath($path);
in my code.
帮助:
- http://framework.zend.com/manual/en/zend.view.scripts.html
- http://forums.zend.com/viewtopic.php?f=69&t=3966#p15370
- http://framework.zend.com/issues/browse/ZF-2353
这篇关于访问模型/控制器中的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文