| « Web Services .NET Grid: Retrieve Data and Show to Data Grid | Zend Framework Registry: Storing Array Values » |
Zend Framework Registry: Setting and Reading Values
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:
- 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.
- Next, we try to call/read this registry. Open your UserController.php within application/controllers.
- 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 blog comments powered by Disqus |

