3
votes

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!

1
You can answer this question to yourself, just start the debugger! Voting to close as not a real question.markus
The documentation is not that bad, once you know the framework, lol! Kidding aside, they did a poor job separating ZF as standalone objects and in the MVC pattern. Some examples completely lack information how to implement a class properly into MVC while other examples only work in an MVC pattern.Adrian World

1 Answers

2
votes

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.