|
|||
|
Hi all.
I am new to Zend Framework and i have some questions that I could not find any answer by google-ing. For example: i have a regular category->products website. In the index controller i have just an index method that will list some welcome messages etc. I also have a controller named products. So in controller Products i have a method list that will handle the listing of products in specific category. So far so good. The HTML page has some sections: on the top there is the header with a menu, on the left is a list of categories, in the center is the content area (different with each controller/method) then on the right a list of hot items, top rated etc. The problem is: how can I populate this sections without having to write a code that will take the categories/hot products/top rated and pass it to the $this->view object in every controller's init() function? I think it can be done using Plugins or Helpers but i could not find anywhere any actual tutorials on this. If anybody has any ideea or maybe a link would be great. Thanks, Adrian |
|
|||
|
Plugins are not so difficult to use. When you implement a plugin , you just need to extend Zend_Controller_Plugin_Abstract , implementing the method you're interested in ( each has a suggestive name , for example dispatchLoopStartup)
PHP Code:
in your bootstrap : PHP Code:
Other alternatives are : - return the response object , and append or prepend your information ( if it's the same) - forward the action to another controller/action |
|
|||
|
Hi khelo.
Thanks for finally answering. I've tried using a plugin several times. The problem is when i try to use the DB inside a plugin. For example if i try this: public function postDispatch(Zend_Controller_Request_Abstract $request) { $categories = new Categories(); } Then the whole page goes BLANK and I can't seem to find the problem. Thanks, Adrian |
|
|||
|
This not necessarily caused by the plugin itself, but it should happen in other parts of your application too if it's not caused by the plugin. I have used this approach many other times and it worked. I assume Categories is extending Zend_Db_Table_Abstract.
A short checklist: If plugins work normal except when using the DB component , it's not a plugin problem. Do you have any adapter registered via Zend_Db_Table_Abstract::setDefaultAdapter somewhere in your index file? Do you have the correct includes? Meaning that your model dir is in the include path? Debug tips: Try running the framework with E_ALL | E_Strict to spot any easy to find problems Try running provided unit tests that come with the framework to spot any problems that you may have in your environment Try using something like APD to debug your app to see where it crashes ( apd is really easy to use) If your model works in other part of your app , register it in Zend_Registry and fetch if from there (this is dumb , it should not work if it doesn't work in your plugin either) Regards |
|
|||
|
Hi Khelo.
I finally found the issue: it seems I wasn't using the latest framework and the errors were not properly shown. After updating to 1.02 I was getting an error saying that mysqli extension was not installed. It works now. Thanks, Adrian |
![]() |
| Thread Tools | |
| Display Modes | |
|
|