Monday 28 September 2009

Another Zend Framework Error - missing index.phtml

Something that isn't made especially clear is the way views and controllers work together. It hints at the issue in the ZF official tutorial here, but provides no clear message.

OK, the scenario - I've just created a new controller:

<?php

class UserController extends Zend_Controller_Action {

public function indexAction(){
echo "You are in the index of User";
}
?>

Running this in the browser by going to http://localhost/public/user will cause this error:

An error occurred

Application error

Exception information:

Message: script 'user/index.phtml' not found in path (C:\wamp\www\application\views\scripts\)

And it also outputs a stack trace and other stuff.

Evidently, there is a missing file issue here. Believe it or not, you need to create a phtml file corresponding to your controller and action! You have to go to the /applications/views/scripts/ directory and create a new folder called 'user' (or whatever you have called your controller), and you need to create a file in it called index.phtml and an additional phtml file for every action you create in all your controllers.

So lame.

No comments:

Post a Comment