phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Zend Framework Intro: Creating Controller

Tag: framework, zend, zend framework, controller, MVC   Category: PHP Framework
post: 09 Apr 2008 read: 2,217


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

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting