Zend Framework Action: GET Parameters


Zend Framework Action Step By Step Tutorial - Part 4: Now, we talk last part or URL in Zend Framework, parameters. Ok, what the rule in Zend Framework? Look this URL sample:
http://hostname/user/name/username/wiwit/gender/man

We can interpret like this:

  1. Controller = user
  2. Action = name
  3. username = wiwit
  4. gender = man

What is your conclusion? Yeah, we have general formula like this:

http://hostname/controller/action/var1/value1/var2/value2/...

How to catch the parameters? Ok, we can learn from sample. Open UserController.php within application/controller. Update became like this:

<?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()
  {
  
    $request = $this->getRequest();
    $this->view->assign('name', $request->getParam('username'));
    $this->view->assign('gender', $request->getParam('gender'));	  
		
    $this->view->assign('title', 'User Name');
  }  
}
?>

Give attention at line 15-17. It is clear, isn't it?

Last, update your view: "name.phtml":

<!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>
  <h2>Gender: <?=$this->escape($this->gender);?></h2>
</body>
</html>


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

Bookmark and Share Tag: framework, zend, zend framework, controller, MVC, actions, parameter, GET Category: PHP Framework Post : April 11th 2008 Read: 37,131

blog comments powered by Disqus