Thursday, October 27, 2011

Re: CakePHP 2.0 - Using a different/unconnected model in a behavior

Found the solution myself:

App::uses('Route', 'Model');

needs to go before the class definition in the Behavior, not inside a
method.

ie.

App::uses('Route', 'Model');

class Routable extends ModelBehavior {

public function foo() {

$Route = new Route();

}

}

On Oct 27, 3:35 pm, "Richard@Home" <richardath...@gmail.com> wrote:
> Hi all
>
> I'm currently re-writing a 1.3 behavior which handles custom routing
>
> In my 1.3 Routable behavior I could pull in a reference to the Route
> model in a method with:
>
> App::Import('Model', 'Route');
> $Route = new Route();
>
> And access it with: $data = $Route->find('all', ... );
>
> I've tried the same thing in 2.0 but I get the following error:
>
> Fatal error: Class 'Route' not found
>
> on the $Route = new Route() line
>
> I've tried using:
>
> App::uses('Route', 'Model');
>
> and that gives the same error.
>
> How do I load a model to use in a behavior method?
>
> Thanks in advance.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

No comments: