Zend Framework Action: Dynamic Content


Zend Framework Action Step By Step Tutorial - Part 1: Previous post, we ever talk little about assign parameter to view. This value is sent from controller. This can happen because Action Controller. I will not talk much detail about Action Controller, but, we will learn implementation of Action Controller in web development.

First, just remembering about passing value from controller to view. We wrote code like this:

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

class IndexController extends Zend_Controller_Action
{
  public function indexAction()
  {
    $this->view->assign('title', 'Hello, World!');
  }
  
}
?>

View will catch with like this:

  <? echo $this->escape($this->title); ?>

If you still don't know what we talk about, please read this series about Zend Framework Introduction.

Ok, now, add one or more parameter such as:

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

class IndexController extends Zend_Controller_Action
{
  public function indexAction()
  {
    $this->view->assign('title', 'Hello, World!');
	$this->view->assign('wellcome','Wellcome to my site. This site is built using Zend Framework. Enjoy it!');
	$this->view->assign('webmaster','Wiwit');
  }
    
}
?>

Then, change you "index.phtml" within application/views/scripts/index.

<!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><? echo $this->escape($this->title); ?></h1>
  <?=$this->escape($this->wellcome);?>
  <p>&nbsp;</p>
  <?=$this->escape($this->webmaster);?>
</body>
</html>

Point your browser to http://localhost/test/zend/helloworld/web_root/. May you get like this:



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, actions, dynamic content Category: PHP Framework Post : April 11th 2008 Read: 35,330

blog comments powered by Disqus