phpeveryday.com

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


Zend Framework Registry: Storing Array Values

Tag: framework, zend, zend framework, registry, zend_registry, array   Category: PHP Framework
post: 16 Apr 2008 read: 816


Zend Framework Registry Step By Step Tutorial - Part 2: In this part we talk how to register array value and how to read them? Every value that we store at registry can we read as array. Ok, follow this steps to understand.

Open again your "index.php" within web_root. Update become like this:


<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', true);
date_default_timezone_set('Europe/London');

$rootDir = dirname(dirname(__FILE__));
set_include_path($rootDir . '/library' . PATH_SEPARATOR . get_include_path());


require_once 'Zend/Controller/Front.php';
require_once 'Zend/Registry.php';

Zend_Registry::set('title',"My First Application");

$arrName = array('Ilmia Fatin','Aqila Farzana', 'Imanda Fahrizal');
Zend_Registry::set('credits',$arrName);


Zend_Controller_Front::run('../application/controllers');

?>

We register a array parameter named "credits" at line 15-16. How to read it?

Ok, we test by update again "UserController.php". Update at indexAction become:


  public function indexAction()
  {
    $registry = Zend_Registry::getInstance();
	
	$title 		= $registry['title'];
	$credits 	= $registry['credits'];
	$strCredit = implode(", ",$credits);
	
    $this->view->assign('name', 'Wiwit');
    $this->view->assign('title', $title);
    $this->view->assign('credits', $strCredit);	
  }

This is another way to read registry. It can we use to read several values from registry.

Ok, before test it. Please update view at index.phtml within application/views/scripts/user. Update with 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>
  credits: <?=$this->escape($this->credits);?>
</body>
</html>

Test by point your browser to http://localhost/test/zend/helloworld/web_root/user/.



Series this article:
Zend Framework Registry: Setting and Reading Values
Zend Framework Registry: Storing Array Values
Zend Framework Registry: Working with Objects

| 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