On Tue, Jun 16, 2009 at 8:56 AM, lakers fan<[email protected]> wrote:
> Hello,
>      I want to write a recursive function in my users controller which will
> be called from the url.
>
> http://localhost/cake/users/recfunction/param1/param2
>
> This recfunction will call itself if needed..
>
> function recfunction(param1, param2)
> {
>      if(condition == true)
>    {
>         recfunction(param1, param2); //get error in this line recfunction
> not defined.
>    }
> }

"function"???  Did you mean action (or method)?

Personally, it sounds strange to me.  Could you tell
us what you're trying to do?

I suggest you study a little bit the object-oriented
paradigm and the web architecture.  It seems that
you're thinking in a desktop/structured way, so using
the incorrect approach to the problem in the web/oop
paradigm.

Once I've said that, about your specific question...
(with comments)

function recfunction($param1, $param2)
// need to specify the variables with the $ sign.
{
     if($condition)
     // is the same and a bit more readable than if($condition == true)
   {
        $this->recfunction($param1, $param2);
        // the correct syntax is something like this, not sure if it
should work... ;-(
        //
        // As a design tip, if I see an action in a controller I
expect it should be
        // called by the browser, not to be recursivelly called inside the code
        // even in that case, maybe you have considering converting your
        // logic to iteractive instead of a recursive approach.  Or, in another
        // point of view, make a recursive call to a private method instead of
        // the same action itself.  Something like:
        //
        // function myAction($p1, $p2) {
        //     $this->_recmethod()
        // //...
        // function _recmethod() {
        //     if( $condition ) $this->_recmethod()
        // }
   }
}

Pay attention that these actions did not return any
value, so you could easily stay in a infine loop.

Did I say that sounds strange to me?

Best regards.

--
MARCELO DE F. ANDRADE
Belem, PA, Amazonia, Brazil
Linux User #221105

http://mfandrade.wordpress.com

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

Reply via email to