Zend Framework Intro: Creating Controller
Zend Framework Step By Step Tutorial - Part 5: The front controller pattern maps the URL requested by the user to a particular member function within a specific controller class. We called as routing and dispatching. The controller class have a strict naming convention requirement. The router calls a function named {actionname}Action() within the {ControllerName}Controller class. This class must be within a file called {ControllerName}.php. If not provide, index will be used. Still confuse? look at this example:
Create a file named "IndexController.php" within application/controllers. Enter following code:
<?php
require_once 'Zend/Controller/Action.php';
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$this->view->assign('title', 'Hello, World!');
}
}
?>
Within the front controller system, the dispatcher expects to find a file called IndexController.php within the application/controllers directory. This file must contain a class called Indexcontroller and, as a minimum, contain a function called indexAction().
| Series this article: Zend Framework Intro: Folder Structure Zend Framework Intro: Explaining Anatomy of Zend Framework Application Zend Framework Intro: Creating Index.php as Single Access File Zend Framework Intro: Creating Apache .htaccess Zend Framework Intro: Creating Controller Zend Framework Intro: Creating View blog comments powered by Disqus |

