Re: Is it possible to write common code in one function and i have to call that function when i was required

2010-04-21 Thread LunarDraco
If the code is meant to transform or in some way CRUD or manipulate
data and it needs to be accessible from multiple controllers, I would
push it down to the model that it is associated with. then in your
code you can call the function as $this->SomeModel->myFunction();
Pushing the code to the model will simplify using it from any
Controller, and it simplifies writing test for the function as well.

MVC -- weight the code in the same order heavy (M)odel, medium (V)iew
and light on the (C)ontroller.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Is it possible to write common code in one function and i have to call that function when i was required

2010-04-20 Thread Fernando Z. Bob
Maybe you can do something like this:


APP_CONTROLLER:
function _mycode(){
$x = 8;
$y = 10;
return $x + $y;
}



USERS CONTROLLER:

function something(){
echo $this->_mycode();
}

function something_else(){
echo $this->_mycode();
}



Bye

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Is it possible to write common code in one function and i have to call that function when i was required

2010-04-20 Thread John Andersen
Or you can do one of the following:
1) If the redundant code is only used in one controller/model, then
extract the redundant code as a new private function in the controller/
model and call it where you need it from the other functions.
2) If the redundant code is used in more than one controller/model,
then extract the redundant code as a new function in the
app_controller/app_model and call it where you need it from the other
functions in each controller/model.
3) If the redundant code can be defined as an independent
functionality, then go with Edinei Luis Cipriani solution.
Enjoy,
   John

On Apr 20, 12:13 pm, Edinei Luis Cipriani  wrote:
> You can make a Componenthttp://book.cakephp.org/view/64/Creating-Components
>
> Best regards
[snip]

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Is it possible to write common code in one function and i have to call that function when i was required

2010-04-20 Thread Edinei Luis Cipriani

You can make a Component
http://book.cakephp.org/view/64/Creating-Components

Best regards
On 20/04/2010, at 05:52, Narendra Padala wrote:


Hi all..!
I am new to cakephp i have problem, i have to use same code in
multiple functions, example



My Problem is, how can i avoid this code redundancy , Is their any the
common code will write one file and i have to include file, or i have
to write the common code in one function and
i have to call in the controller functions. Please help me
outthanks in advance

Check out the new CakePHP Questions site http://cakeqs.org and help  
others with their CakePHP related questions.


You received this message because you are subscribed to the Google  
Groups "CakePHP" group.

To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this  
group at http://groups.google.com/group/cake-php?hl=en


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Is it possible to write common code in one function and i have to call that function when i was required

2010-04-20 Thread Narendra Padala
 Hi all..!
 I am new to cakephp i have problem, i have to use same code in
multiple functions, example



My Problem is, how can i avoid this code redundancy , Is their any the
common code will write one file and i have to include file, or i have
to write the common code in one function and
i have to call in the controller functions. Please help me
outthanks in advance

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en