![]() |
|
|||
|
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 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');
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 |
|
|||
|
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. |
|
|||
|
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. |
|
||||
|
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 |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| Designed by: Miner Skinz |
Powered by vBulletin® Version 3.8.4 Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Search Engine Friendly URLs by vBSEO 3.1.0 |
![]() |