break the code for controller file

Showing 1-6 of 6 messages
break the code for controller file mans 4/1/08 5:07 AM
My controller files code has gone very long. I want to break it in
different files.
thanks in advance
Re: break the code for controller file Dardo Sordi Bogado 4/1/08 5:21 AM
Well, two things:

1. Fat models, skinny controllers.
2. Create and use components.

Re: break the code for controller file mans 4/2/08 3:28 AM
but these functions are not reusable and I am also not interesting in
making components.
Is their not some solution like (as in simple php we use include or
require) we made some file and include it in controller ?


On Apr 1, 5:21 pm, "Dardo Sordi Bogado" <dardoso...@gmail.com> wrote:
> Well, two things:
>
> 1. Fat models, skinny controllers.
> 2. Create and use components.
>
Re: break the code for controller file Adam Royle 4/2/08 3:42 AM
Well, CakePHP is just regular PHP, so you can still do includes or
whatever you want. What is your controller code doing that takes so
many lines of code?

Adam
Re: break the code for controller file manuj bansal 4/2/08 3:55 AM
I have tried it down by making simple php file (quality.php) and
then add functions in quality.php from animals controller
then i use include("quality.php") in animals controller
but it doesn't work
Re: break the code for controller file simonell...@googlemail.com 4/2/08 4:09 AM
You can't just include procedural functions in the middle of a class
and expect them to be methods. Includes are not a pre-compiler
directive. What you'll need to do is to define every function at least
in your controller class file, then you could in theory include the
contents of that function. However, this would be slightly crazy, and
lead to a lot of includes (one per function that you extracted).

Also, if the code really can't be moved to the models / refactored to
generalize into a superclass, or reusable methods then there is
probably something wrong with your design. The main reason to split
things like controllers up would be to allow for reuse (see
components).

Bear in mind as well that you have to have a pretty compelling reason
to split the file up. Every include you use will increase the parse
time, and add overhead to your application. PHP is not after all a
compiled language. If your problem is code manageability you may be
better served by getting an editor that folds functions (eg eclipse
pdt).

Simon
http://www.simonellistonball.com/