ryan
ryan

Reputation: 333

script 'index.phtml' not found

I have used following code in IndexController:

$view = new Zend_View(array('scriptPath' =>'C:\Users\398853\Documents\NetBeansProjects\PhpProject3\application\views\scripts')); 
 echo $view->render('index.phtml');

But error is displayed as script 'index.phtml' not found in path (C:\Users\398853\Documents\NetBeansProjects\PhpProject3\application\views\scripts/)

I think the error occured because in script path '/' added instead of '\' at end.If yes then what is the solution for that?

Upvotes: 1

Views: 2940

Answers (5)

Benj
Benj

Reputation: 1204

Using IDEs, check the correct upload of your files. Just struggled twenty minutes to find that.

Upvotes: 0

Hikaru-Shindo
Hikaru-Shindo

Reputation: 1901

You need to pass the relative path to the script with the script path as base path so:

$view = new Zend_View(array('scriptPath' =>'C:\Users\398853\Documents\NetBeansProjects\PhpProject3\application\views\scripts'));
echo $view->render('index/index.phtml');

Should work. This is expecting you mean index action of index controller.

The directory separators are not important to PHP. If you want to be 100% on the save side use the constant DIRECTORY_SEPARATOR like this:

$path = array(APPLICATION_PATH, 'views', 'scripts');
$view = new Zend_View(array('scriptPath' => implode(DIRECTORY_SEPARATOR, $path));

Upvotes: 1

Brian Driscoll
Brian Driscoll

Reputation: 19635

The direction of the slash actually shouldn't matter. You're getting this error because there is no file named index.phtml in ..\views\scripts

Upvotes: 0

Marc B
Marc B

Reputation: 360692

In PHP, always use forward slashes for paths. PHP will translate to the OS-specific directory separator for you:

$view = new Zend_View(array('scriptPath' =>'C:/Users/398853/Documents/NetBeansProjects/PhpProject3/application/views/scripts')); 

When you use backslashes, PHP has NO way to know that you're actually specifying a path, so it treats them as escapes, so in effect your path came out to be:

C:Users398853DocumentsNetBeansProjectsetc....

which is highly unlikely to exist on your machine.

Upvotes: 0

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76880

You should always use / instead of \ when you specify paths as it works both in windows and linux

$view = new Zend_View(array('scriptPath' =>'C:/Users/398853/Documents/NetBeansProjects/PhpProject3/application/views/scripts'));

And you should definitely use a relative path, not an absolute one as you are doing i think

Upvotes: 0

Related Questions