Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-28-2007, 07:47 AM
Junior Member
 
Join Date: Sep 2007
Posts: 10
Default Framework Templating

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-02-2007, 08:05 AM
Junior Member
 
Join Date: Oct 2007
Posts: 5
Thumbs up

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:
//somewhere 
class FooPlugin extends  Zend_Controller_Plugin_Abstract 
{
     
    public function 
postDispatch(Zend_Controller_Request_Abstract $request)
    {
        
$response =  $this->getResponse();
        
$view Zend_Controller_Front::getInstance()->getHelper('viewRenderer')->view;
        
$view->foo 'something';
        
$response->prepend('header',$view->render('yourheader.phtml');
    }


in your bootstrap :
PHP Code:
//......
$controller Zend_Controller_Front::getInstance();
$controller->registerPlugin('FooPlugin');
//etc 
I just gave you a simple example on how you can use a plugin , it;s not necessary the solution to your problem. The above examples assumed the view object was already initialized , but you can use a new instance of view if you want, or you can use Zend_Registry to share same view object across your application , depending on your needs.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-03-2007, 02:57 PM
Junior Member
 
Join Date: Sep 2007
Posts: 10
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-04-2007, 09:37 PM
Junior Member
 
Join Date: Oct 2007
Posts: 5
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-08-2007, 07:57 AM
Junior Member
 
Join Date: Sep 2007
Posts: 10
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:12 AM.