Helping ordinary people create extraordinary websites!

Zend Framework Tutorial

By Lyndon Baptiste
2008-08-13

Actioning Requests

Let's set up two files, make sure things are in order and then we'll get to the discussion. Revisit Figure 1 for a second. In the modules directory, as depicted to the left of the illustration, create a folder and name it "default". In "default" create three folders: one for your controllers, associated models and views. In the "views" folder create a folder named "scripts". The norm is that in the "scripts" folder you will have folders for your views which relate to the name of the controllers nested in the module. Now that this file structure is set up go to the controllers directory. Create a file call IndexController.php and paste following code into it:

<?php
require_once 'Zend/Controller/Action.php';

class IndexController extends Zend_Controller_Action {
public function init() {
$this->initView();
}

public function preDispatch() {

}

public function postDispatch() {

}

public function indexAction() {
$this->render();
}
}?>

Now that's over go to the views directory. Create a file called index.phtml and paste the following code into it:

<p>
Page body from view will be rendered. This corresponds to the content key that was set up in the
associative array with the key 'content'.
</p>

Before you fire up your webserver and make a request go to the layouts directory in the application folder. Create a file called default.phtml and paste the following code:

<html>
<head>
<title></title>
</head>

<body>
<div>
<h1>Page header template here</h1>
</div>
<div>
<?php echo $this->layout()->content; ?>
</div>
<div>
<h1>Page footer template here</h1>
</div>
</body>
</html>



Tutorial pages:
 11 Votes

You might also want to check these out:


Leave a Comment on "Zend Framework Tutorial"
You must be logged in to post a comment.

Link to This Tutorial Page!


GET OUR NEWSLETTERS