PHPEveryday.com PHP and Web Development Tutorial
What are you looking for?


Table of Content
Zend Framework Tutorial

Learn Zend Framework Intro
Zend Folder
Zend Anatomy
Zend Access File
Zend .htaccess
Zend Controller
Zend View

Learn Zend Framework Action
Zend Content
Zend URL Controller
Zend URL Action
Zend GET
Zend Including

Learn Zend Framework Database
Zend Database
Zend Input Form
Zend Inputing Data
Zend Expressions
Zend Data List
Zend Editing Form
Zend Updating Data
Zend Update Query
Zend Deleting Data
Zend Delete Query
Zend Action

Learn Zend Framework Registry
Zend Values
Zend Array
Zend Objects

Learn Zend Framework Config
Zend Array Config
Zend File Config
Zend INI File
Zend XML File

Learn Zend Framework Login
Zend Database
Zend Form Login
Zend Authentication
Zend Fatal error
Zend Protected
Zend Logout
Zend Switching

Learn Zend Framework Session
Zend Session
Zend Namespace
Zend Session Data
Zend Value
Zend Lock
Zend Expiration

Zend Framework Action: URL Structure and Action


Zend Framework Action Step By Step Tutorial - Part 3: Just remember, we have rule like this: http://hostname/controller/action/parametes. We have talked about controller. Now, we discuss next part, action.

For simply, action is method in our class at controller. Look at our code:

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

class UserController extends Zend_Controller_Action
{
  public function indexAction()
  {
    $this->view->assign('name', 'Wiwit');
    $this->view->assign('title', 'Hello');
  }
    
}
?>

Above, we have action name "index". Naming in Zend Framework, add with Action. Thus, we have action "indexAction". When we call this controller (such as user), but we don't specify action, it will call indexAction as default.

Now, add a method in there, example "nameAction" such as:

  public function nameAction()
  {
    $this->view->assign('name', 'Wiwit');
    $this->view->assign('title', 'User Name');  
  } 

Below, complete our userController:

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

class UserController extends Zend_Controller_Action
{
  public function indexAction()
  {
    $this->view->assign('name', 'Wiwit');
    $this->view->assign('title', 'Hello');
  }

  public function nameAction()
  {
    $this->view->assign('name', 'Wiwit');
    $this->view->assign('title', 'User Name');  
  } 
    
}
?>

Next, create a file named "name.phtml" within views/scrips/user. Enter following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? echo $this->escape($this->title); ?></title>
</head>

<body>
  <h1><?=$this->escape($this->title);?>, <?=$this->escape($this->name);?></h1>
</body>
</html>

Now, point your browser to http://localhost/test/zend/helloworld/web_root/user/name



Series this article:
Zend Framework Action: Dynamic Content
Zend Framework Action: URL Structure and Controller
Zend Framework Action: URL Structure and Action
Zend Framework Action: GET Parameters
Zend Framework Action: Including Header and Footer


Tag: framework, zend, zend framework, actions, url structure, controller Category: PHP Framework Post : April 11th 2008 Read: 5,840 Bookmark and Share

blog comments powered by Disqus


Database Tutorial
  • Learn PHP MySQL
  • Learn PHP ADOdb
  • Learn PHP Data Object/PDO
  • Learn PHP XML
  • Learn PHP SimpleXML
Security Tutorial
  • Learn PHP Security
  • Learn HTTP Authentication
  • Learn PHPSecureSite
Framework Tutorial
  • Learn CodeIgniter
  • Learn Joomla
  • Learn Smarty
  • Learn Zend Framework
Template Tutorial
  • Learn Joomla Template
  • Learn WordPress Template
API Tutorial
  • Learn Facebook
JS Framework Tutorial
  • Learn MooTools
  • Learn JQuery
AJAX Tutorial
  • Learn AJAX in 10 Minutes
  • Learn AJAX Client Side
  • Learn AJAX PHP
  • Learn AJAX Remote Server
  • Learn AJAX Repetitive
  • Learn AJAX MySQL
  • Learn AJAX Grid
Web Services Tutorial
  • Learn Web Services NuSOAP
  • Learn Web Services WSDL
  • Learn Web Services WSDL Array
  • Learn Web Services .NET Grid
  • Learn Web Services WDDX
Package Post
  • Joomla Intro
  • Joomla Component
  • Joomla Module
  • Joomla MVC
  • Joomla MVC Backend
  • PostNuke Intro
  • Zend Framework Intro
  • Zend Framework Action
  • Zend Framework Database
  • Zend Framework Registry
  • Zend Framework Config
  • Zend Framework Login
  • Zend Framework Session
  • PHP Array Tips
  • PHP File Tips
  • PHP Email
  • PHP Ms Excel
  • PHP Pattern
  • PHP SMS
  • Flash Database
  • PHP Multitier
  • jQuery Introduction
  • jQuery Selectors
  • Portable Web Server
  • Web Mobile Intro
  • Drupal Installation
  • Drupal Configuration