Having 500 lines per method is a code smell, i.e. a signpost you should refactor. The best start to this is splitting your monster method (start method by method) into smaller bitesize private functions. It's easy to do, just start by putting each new step or block of functionality in the code into a new private method with a name which describes that separated functionality.
Once you have that break up in place, do the same for other monsters. Once all the monsters are reduced to a few dozen imps (okay, the analogy is getting thin ;)) you probably have places where they overlap - i.e. another sign to combine smaller methods where are too similar, or doing the same things, or duplicate the same code over and over again. After that exercise, then (and only then) should you consider splitting code into other controllers, or a controller/action setup. If that's not desireable (and honestly even if it is), just grab all those private methods and create a new class (I'd call it a "Controller Helper") or even classes. Then you can create new instances of these to use in your controller methods - and hey presto your controller code is now much reduced with all the complicated, and potentially reusable code in a nice separate family of classes - a mini-library of sorts. Hopefully this shines a little light on how to keep controllers minimal by refactoring duplicate/complex code into helper classes or libraries. :) Regards, Pádraic Pádraic Brady http://blog.astrumfutura.com http://www.patternsforphp.com ----- Original Message ---- From: Matthew Weier O'Phinney <[EMAIL PROTECTED]> To: [email protected] Sent: Friday, April 20, 2007 12:08:03 PM Subject: Re: [fw-general] Action files -- agatone <[EMAIL PROTECTED]> wrote (on Friday, 20 April 2007, 02:28 AM -0700): > I'm sorry if this was already discussed but i could find any topics about it. > Let's say we have in our controllers folder this action file : > > class IndexController extends Zend_Controller_Action { > function indexAction() { ... } > function addAction() { ... } > function removeAction() { ... } > function editAction() { ... } > function deleteAction() { ...} > .... etc. ... > } > > So at all this actions file could easily have 500+ lines, what is (in my > oponion) very bad. > Wouldn't be easier if actions could be in separate files - more simple > structure ... ? > > Any ideas ? Besides working on the Zend MVC, I'm also the author of Cgiapp, a PHP port of CGI::Application. In CGI::Application, the rule of thumb is that if you have more than seven run modes (equivalent to action methods in ZF), then you need to refactor. I'd suggest that you should probably refactor such a controller into multiple controllers with their own subsets of actions. Alternatively, consider writing your own dispatcher that dispatches to controller/action.php. This would be fairly trivial to accomplish -- but is not likely to go into the ZF core any time soon. -- Matthew Weier O'Phinney PHP Developer | [EMAIL PROTECTED] Zend - The PHP Company | http://www.zend.com/ __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
