phpeveryday.com

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


Zend Framework Registry: Setting and Reading Values

Tag: framework, zend, zend framework, registry, zend_registry   Category: PHP Framework
post: 16 Apr 2008 read: 1,207


Zend Framework Registry Step By Step Tutorial - Part 1: What is registry? It is like global storage. We just register values then we can use throughout application. For example, we can store name of application, thus every time we need to display name of application, we just call from registry.

To use registry, we call registry.php from Zend Framework:


require_once 'Zend/Registry.php';

Ok, we practice using registry. We still use our previous practice. Please read that tutorial before. Then, follow this steps:

  1. Open "index.php" within "web_root". Enter line 11 - 13:
    
    <?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");
    
    
    Zend_Controller_Front::run('../application/controllers');
    
    ?>
    

    We set a parameter named "title". We put a value for this parameter.

  2. Next, we try to call/read this registry. Open your UserController.php within application/controllers.
  3. Update indexAction like this:
    
    public function indexAction()
    {
        $title = Zend_Registry::get('title');
        $this->view->assign('name', 'Wiwit');
        $this->view->assign('title', $title);
    }
    

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

You may remember a function at PHP that have function like this, define(). Yup, it is like register global parameter.



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