php – Zend中的setScriptPath无法找到文件
我正在使用Zend框架书,并且在我更改默认视图位置的示例上停留了好几天.方法如下:
$this->view->setScriptPath("/views/"); $this->render("news"); 我将news.phtml文件放在views目录中(而不是默认的views / scripts / artist,但我得到的是一条消息,说明找不到页面.我已尝试过很多来自网络的方法,比如输入 $this->view->setScriptPath("/application/views/"); 要么 $this->view->setScriptPath(APPLICATION_PATH."/views/"); 但都没有用. 有人可以赐教吗? 为了提高清晰度,我有点怀疑它与我的机器设置有关.我在Mac 10.7上运行,我已经激活了内置的PHP和Apache.既然Zend提供了自己的堆栈,那么php.ini等设置文件会不会有任何冲突? 更多编辑: public function newsAction() { //Check if the user is logged in //Get the user's id // //Get the artists $artists = array("Thievery Corporation","The Eagles","Elton John"); //Set the view vairables $this->_helper->viewRenderer->setRender('news'); $this->view->setScriptPath(APPLICATION_PATH.'/views/'); $this->_helper->viewRenderer->setNeverController(true)->setRender('news'); } 我将news.phtml放在views目录中.我输入的URL是http:// localhost:10088 / loudbite / artist / news. artistController位于controllers文件夹中.仍然无法正常工作. 解决方法
使用setScriptPath()或addScriptPath时,需要指定目录的绝对路径或相对于当前目录的路径.为了便于携带,最好使用绝对路径.
调用Zend_View :: render()时,必须传递脚本名称,包括其扩展名. 根据您的上一个示例,尝试这样的事情: $view->setScriptPath(APPLICATION_PATH . '/views/'); $html = $view->render('news.phtml'); 只要确保路径正确.我的示例假设您在应用程序文件夹中有视图. 编辑: $this->_helper->viewRenderer->setRender('news'); 这告诉视图渲染器查找视图脚本news.phtml而不是您的操作名称.但是,它仍然在views / scripts / controller /中查找news.phtml.因此,您还需要进行以下更改: // set view script path to the base of the views folder $this->view->setScriptPath(APPLICATION_PATH . '/views/'); $this->_helper ->viewRenderer ->setNeverController(true) // do not render into controller subdirectories ->setRender('news'); // set render script to news.phtml 当你使用Zend Application时,它会自己进行视图渲染,所以除非你试图直接渲染html,否则你不应该自己使用Zend_View.控制器操作方法完成后,Zend Application将自动呈现视图脚本并尝试将其与任何布局一起输出到浏览器.如果您确实创建了自己的Zend_View,则需要在操作完成之前终止请求,以免呈现任何其他内容.还有一些方法可以禁用布局或视图渲染作为替代方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |