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


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-16-2008, 07:47 AM
Junior Member
 
Join Date: Apr 2008
Location: Germany, Hamburg
Posts: 11
Default Custom Action Helpers - where to put them?

Hi,

as I said somewhere else before : I'm pretty new to the Zend Framework. So, here is another question I have.

Where do I have to put an action helper considering Zend Framework best pratices? At default there is only a helpers path beneath the views path. I guess, that's the place for view helpers only, is it?

What else do I have to beware of, so the helper gets loaded successfullly using $this->_helper->getHelper('MyBeautifulHelper') within the action controller. Any pitfall ?

[edit]
A small addition: I'm thinking of an action helper checking in an action controller, whether a user is logged in and may perform some action or not.
[/edit]

Thanks in advance for your help.

Sebastian

Last edited by sebastian : 04-16-2008 at 07:49 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-16-2008, 02:23 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 119
Default

I tend to put any and all classes in the library, be it an action helper, view helper, new base controller, what ever... If its used by more than one module or controller I put it in my library. Follow the ZF naming conventions and Zend_Loader can handle all the loading. If its a view helper and is only needed for this one module then I put it in the module's view/helpers/ path.


library
- Zend
- - ...
- MyLib
- -...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-16-2008, 02:40 PM
Junior Member
 
Join Date: Apr 2008
Location: Germany, Hamburg
Posts: 11
Default

Ok, I see. Thanks for your answer. I tend to seperate files by use, meaning I would put view helpers and action helpers each in it's own folder.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-24-2008, 10:03 AM
Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 52
Send a message via MSN to Leif.Högberg
Default

While I somewhat agree with Elemental I tend to separate my lib from my application. Meaning that things that aren't application specific ends up in the lib. Everything else ends up somewhere in the application. That way I end up with a neatly packaged reusable lib.

That being said I also have an application specific lib folder for application specific lib files(obviously).

To answer your question I would create a helper dir in your controller dir (ie /modules/mymodule/controller/helpers/) and drop the helpers there.
To call them you need to add the path tho, $this->_helper->addPath() from your controller for instance. Adding the path could/should be done elsewhere if it's a recurring thing.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-24-2008, 02:20 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 119
Default

That's an excellent idea. You could load the path based on the requested module via a plugin, much as you would a model. See this post for help with the plugin.
__________________
Zend Framework Resources: Zend Webinars | Reference Manual | API Docs | Books | FreeNode: #zftalk
Getting Started Tutorials: Getting started with ZF | Getting started with Zend Auth
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 08:41 PM.