2009-10-21 60 views
1

我正在通过Apress的书“Beginning Zend Framework”的工作方式 - 我正努力获得其中一个示例。zend set/getScriptPath问题:

目标是使用setScriptPath来规避标准目录结构。本教程不是将操作的相关视图脚本存储在脚本目录中,而是要求您将其保存在项目目录中的其他位置。我将它存储在应用程序的根目录中。这里的代码:

public function updateAction() 
    { 
    //get the artists 
    $artist = array("Thievery Corporation","The Eagles","Elton John"); 

    //set view variables 
    $this->view->artists = $artist; 

    //locate the view 
    $this->view->setScriptPath('/application/'); 
    $this->render("update"); 
    } 

但是,当我尝试去www.domain.com/account/update - 它说它找不到脚本。我需要知道的是如何定义相对于框架结构的文件夹的位置。我在现有脚本文件夹内的脚本上使用了getScriptPath,但它们返回绝对硬盘路径,我不确定是否正确 - 当然,我无法使用update.phtml脚本中的getScriptPath,因为我可以不加载它。

任何能帮助我的zend大师?

回答

3

解决这个问题的最简单方法是在索引文件中定义一个包含应用程序绝对路径的常量。

define('APPLICATION_PATH', '/path/to/your/application/'); 

//Bootstrap is called somewhere here. 

这使您可以在需要设置/添加脚本路径时使用它。

$this->view->setScriptPath(APPLICATION_PATH); 
//$this->view->addScriptPath(APPLICATION_PATH . 'some/other/dir/'); 

希望这会有所帮助。

+0

doh,我的错误 - 好吧,不是真的。我需要实例化Zend_View对象 - 本教程未在动作代码中显示。我的坏 - 谢谢你的帮助! – sunwukung 2009-10-21 10:50:49

+0

如果您只是想添加到堆栈而不是替换当前路径,您还可以使用$ this-> view-> addScriptPath(...)。 – voidstate 2011-06-06 11:27:45

3

我在/public/index.php文件喜欢

define('APPLICATION_PATH', dirname(__FILE__) . '/../application/'); 

。因为它是可重复使用和防呆的:)