phpeveryday.com

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


Zend Framework Action: URL Structure and Action

Tag: framework, zend, zend framework, actions, url structure, controller   Category: PHP Framework
post: 11 Apr 2008 read: 1,361


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

| 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