Rei
Rei

Reputation: 821

Where are the instantiated objects stored in zend framework?

I'm a beginner in Zend Framework and I find it hard to understand their documentation. The only PHP Framework I have used was CodeIgniter.

I am used to this method in utilizing libraries:

//load the My_Library class and assign the object to $this->myLibrary property
$this->load->library('my_Library');  //CodeIgniter way

public function index()
{
   $this->my_Library->method();  //make use of the methods in the loaded library
}

So far I'm figuring out how this code works in zend, say in the bootstrap class:

protected  function _initSetDoctype()
{
        $doctypeHelper = new Zend_View_Helper_Doctype();
        $doctypeHelper->doctype('XHTML1_STRICT');  
}

And in the layout.phtml file we can put:

<?php echo $this->doctype() ?>

My question is: Since I have instantiated a new Zend_View_Helper_Doctype(); How did ZF assign $this->doctype and made this available in view? Is there some kind of storage where these values update the view object?

I'm trying to find out how the flow works in zend so I could have a better understanding on how to make use of its resources. Sorry for my English if it's hard to understand @_@ Thank you very much!

Upvotes: 3

Views: 140

Answers (1)

Marcin
Marcin

Reputation: 238319

Usually ZF uses Zend_Registry to store instances of objects that it creates. The specific example that you provided (i.e. _initSetDoctype) works, because constructor of Zend_View_Helper_Doctype will check if it is already stored in Zend_Registry or not. So, in your bootstrap, new Zend_View_Helper_Doctype() will store doctype info in a registry (because it is created for the first time), and than in the layout.phtml, the stored value in the registry will be retrieved.

Other ZF resources (or objects) such as Zend_View, Zend_Layout, are also stored and access through registry.

Off course, you can also store your own objects (or whatever) in a registry. This way, you will be able to access them in every place of you ZF app.

Upvotes: 2

Related Questions