Sorry #2 did work. It returns either a single directory or an array of
directorys, depending on what set up is used and if a module name was
specified. I got intrupted when writing the e-mail, and hit send to fast...

http://framework.zend.com/issues/browse/ZF-2910  - I found the same function
in ViewRender.php. Thought it looked filmiar. 

I would, could, use the active module directory before the dispatch, but I
didn’t see how this was posible. 

However, I could get the information in the action controller - which works
for me.

Terre 

-----Original Message-----
From: Matthew Weier O'Phinney [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 18, 2008 1:26 PM
To: [email protected]
Subject: Re: [fw-general] Re: [fw-mvc] Get module directory?

-- Terre Porter <[EMAIL PROTECTED]> wrote (on Tuesday, 18 March
2008, 12:57 PM -0400):
> A couple thoughts,
> 
> 1. the request object does not appear to be available until after a
> $front_controller->dispatch() call
> 
> 2. there is a function that returns the controllers directory 
> $front_controller->getControllerDirectory($modulename optional)
> 
> However, neither is available (in my code) until after the dispatch 
> call. It then becomes accessable in the IndexController functions.

Regarding (2): it will work when:
 
 a) you've setup your controller directories already
 b) you provide the name of a module to the method.

It doesn't require that the dispatch is made. 

However, (1) makes sense: you can't know what the current module is without
already being in the dispatch loop. The current module is the module in
which the currently executing controller lives -- whether this was the
requested controller, or one to which we've forwarded, or one which we've
invoked using the action() view helper. 

A getModuleDirectory() or similar method would simply return null or false
if there is no request, or no module set in the request object.

> 
> Something like this ...
> 
> define('APPDIR', realpath(dirname(__FILE__).'/../').'/application');  
> 
> $controller = Zend_Controller_Front::getInstance();
> $controller->addModuleDirectory(APPDIR.'/modules');
> $controller->setParam('noViewRenderer', true); 
> $controller->throwExceptions(true);
> $controller->dispatch();
> 
> The modules directory contains: 
> news
> -- controllers
> --- IndexController (news_index)
> default
> -- controllers
> --- IndexController (index)
> admin
> -- controllers
> --- IndexController (admin_index)
> 
> Then in the IndexController..
> 
> $cDir =
> $this->getFrontController()->getControllerDirectory($this->_getParam('
> module
> '));
> 
> $cDir equals:
> 
> Testsite/
>  string(54) "/home/tbnlogin/application/modules/default/controllers"
> 
> Testsite/news
>  string(51) "/home/tbnlogin/application/modules/news/controllers"
> 
> Testsite/admin
>  string(51) "/home/tbnlogin/application/modules/admin/controllers"
> 
> This was the only way I could find to provide me with the current 
> module directory.
> 
> I can now trim off the "controller" directory name
> $this->getFrontController()->getModuleControllerDirectoryName() and 
> replace it with templates or some other directory to be contained 
> under the module directory.
> 
> In my case the plan is to pass the directory to a custom smarty/view 
> to allow for a global templates directory and a module specific directory.
> 
> Or at least that’s the plan...
> 
> Terre
> 
> -----Original Message-----
> From: Jurriën Stutterheim [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, March 18, 2008 10:28 AM
> To: fw-general List
> Subject: [fw-general] Re: [fw-mvc] Get module directory?
> 
> Here you go :-) http://framework.zend.com/issues/browse/ZF-2910
> 
> On Mar 18, 2008, at 2:28 PM, Matthew Weier O'Phinney wrote:
> 
> > -- Jurriën Stutterheim <[EMAIL PROTECTED]> wrote (on Tuesday, 
> > 18 March 2008, 01:58 PM +0100):
> >> Getting the module directory can be used for access to the :module/ 
> >> models directory, or custom directories inside the module directory.
> >> E.g.
> >> :module/forms , :module/config (for module specific configs)
> >>
> >> Of course it's easy to do dirname($controllerDirectory), but it 
> >> would be more convenient to have the module directory available 
> >> from a method inside the frontcontroller.
> >>
> >> Suggestion for the method signature in the front controller:
> >>
> >> public function getModuleDirectory($module = null);
> >>
> >> It returns the module directory for the current module, unless 
> >> $module is specified. In that case it would return the module 
> >> directory for the specified $module.
> >
> >
> > That makes sense -- and particularly in light of the proposed 
> > ModelLoader action helper. Cut and paste that into an issue for the 
> > issue tracker, please. :-)
> >
> >
> >> Op Di, maart 18, 2008 13:19 schreef Matthew Weier O'Phinney:
> >>> -- thurting <[EMAIL PROTECTED]> wrote (on Monday, 17 March 
> >>> 2008,
> >>> 11:01 PM -0700):
> >>>
> >>>> Is the only way to quickly get the current module directory 
> >>>> through ViewRenderer::getModuleDirectory()?  I see why it's 
> >>>> there, but it feels like a strange place for it.
> >>>
> >>> That's actually a convenience method for the following, 
> >>> simplified,
> >>> code:
> >>>
> >>>
> >>> $front = Zend_Controller_Front::getInstance();
> >>> $request = $front->getRequest();
> >>> $dir = $front->getControllerDirectory($request->getModuleName());
> >>>
> >>>
> >>> The ViewRenderer needs to determine the current module directory 
> >>> dynamically in order to set view script paths. No other shipped 
> >>> components need such functionality, and so it's self-contained in 
> >>> the ViewRenderer.
> >>>
> >>>
> >>> What do you need this functionality for in a more general sense?
> >>>
> >>>
> >>> --
> >>> Matthew Weier O'Phinney
> >>> PHP Developer            | [EMAIL PROTECTED]
> >>> Zend - The PHP Company   | http://www.zend.com/
> >>>
> >>>
> >>>
> >>
> >>
> >
> > --
> > Matthew Weier O'Phinney
> > PHP Developer            | [EMAIL PROTECTED]
> > Zend - The PHP Company   | http://www.zend.com/
> >
> >
> 
> 

--
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to