phpeveryday.com

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


Zend Framework Action: Dynamic Content

Tag: framework, zend, zend framework, actions, dynamic content   Category: PHP Framework
post: 11 Apr 2008 read: 1,820


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

| 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