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


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-10-2007, 01:38 PM
pinano's Avatar
Junior Member
 
Join Date: Jul 2007
Location: León, Spain
Posts: 4
Default View Helpers and the modular structure

I've already posted this in another thread, but I think it's worth starting a new thread on this topic, since I think it's something that people using the modular structure will find sooner or later.

The thing is... my application is structured following the conventional modular structure:

Code:
/application
   /config
   /library -> my custom plugins, etc
   /logs
   /models
   /modules
     /default
         /controllers
         /views
            /filters
            /helpers
            /scripts
    /other-module
    /etc...
/library
   /Zend
   /3rd party libraries...
/public_html
I think it is very convenient to be able to use certain custom view helpers throughout all the modules (just the same way we have plugins that are registered in the bootstrap file), but I might be missing something with the helper paths, since the only way I've found to do this is a bit awkward.

I understand that, at least in the current version of the framework (1.0.0), views are instantiated by the controllers, so there's no way to access the views from the bootstrap file, hence it's not possible to set view helper paths from there.

If I want to set a path to store all of my "global" view helpers, what I'm doing right now is overriding all of my controllers' "init" function to add a line like this:

Code:
$this->view->addHelperPath('./../application/library/mycustomviewhelpers');
Altough this works, doing this is a pain, and it's not very elegant. By the way, it's pretty ugly to have to deal with relative paths in the controllers... I know, I could set up the path in the bootstrap and store it in the registry to retrieve it in the controller, but that wouldn't keep me from rewriting the init() methods.

Does anyone know of a better way to achieve this without having to rewrite each an every init() method? Maybe the solution is very simple and I'm just being a little stupid...

Last edited by pinano : 07-10-2007 at 01:39 PM. Reason: mispelling
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-10-2007, 02:28 PM
Junior Member
 
Join Date: Jul 2007
Posts: 1
Default

Unless I'm mistaken, if you manually instance your view class in your bootstrap, via the ViewRenderer helper (which gets registered in the Helper Broker), then that one will be used throughout your controllers.

Zend Framework: Documentation

Before you register your Zend_View class with the Helper, just assign the path there.

As a more generic solution to these kinds of problems, you may also want to consider using an intermediate Controller subclass for your application-wide settings, so that you can do app-specific stuff like this once only.

So instead of having Your_Controller (for example) extend Zend_Controller_Action directly, you create App_Controller that extends Zend_Controller_Action (and optionally <Module>_Controller that extends App_Controller if your are using modules, and have <Module> be the name of your module) and then have Your_Controller extend either App_Controller or <Module>_Controller as is appropriate.

This technique allows you to put stuff in the init() methods of App_Controller and <Module>_Controller that get applied to all the subclass controllers easily and once only, and makes maintenance easier and keeps your code more elegant.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-11-2007, 06:47 AM
pinano's Avatar
Junior Member
 
Join Date: Jul 2007
Location: León, Spain
Posts: 4
Default

I had already thought about extending Zend_Controller_Action, but this looks inelegant to me, at least for such little improvement (adding a helper path in the view)...

I will try the solution you propose, that of instancing the view in the bootstrap via the ViewRenderer helper...

Thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-21-2007, 12:03 AM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 121
Default

Generally we set view helper paths in the bootstrap....

First, you must get a ViewRenderer instance then set your view instance to it...
WebSVN - spotsecng-backup - Rev 187 - /branches/potatobob/src/webconsole/htdocs/index.php
__________________
Zym Framework - A Zend Framework extension library w/ demo app

SpotSec Blog:
http://spotsec.com/blog
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 09:03 PM.