zend set/getScriptPath problem:
I'm working my way through the Apress book "Beginning Zend Framework" - and am struggling to get one of the examples to work.
The aim is to circumvent the standard directory structure using setScriptPath. Rather than storing the action's associated view script in the scripts directory, the tutorial asks you to save it els开发者_运维技巧ewhere in the project directory. I've stored it in the root of application. Here's the code:
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");
}
However, when I try to go to www.domain.com/account/update - it says it can't locate the script. What I need to know is how to define the location of a folder relative to the framework structure. I've used getScriptPath on scripts within the existing script folder, but they return absolute hard-disk paths, which I'm not sure is correct - and of course I can't use getScriptPath from the update.phtml script, because I can't load it.
Any zend gurus able to help me?
The simplest way to address this is by defining a constant containing the absolute path to your application in your index file.
define('APPLICATION_PATH', '/path/to/your/application/');
//Bootstrap is called somewhere here.
This allows you to use this whenever you need to set/add a script path.
$this->view->setScriptPath(APPLICATION_PATH);
//$this->view->addScriptPath(APPLICATION_PATH . 'some/other/dir/');
Hope this helps.
I prefer
define('APPLICATION_PATH', dirname(__FILE__) . '/../application/');
in my /public/index.php
file. Because it's reuseable and fool-proof :)
精彩评论