Quantcast

custom route classes in 2.x?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

custom route classes in 2.x?

lowpass
In routes.php I've changed:

App::import('Lib', 'routes/PageSlugRoute');

to:

App::uses('PageSlugRoute', 'Lib/routes');

My custom class is in app/Lib/routes/PageSlugRoute.php

This throws a warning:
Warning (2): Unknown class passed as parameter
[CORE/Cake/Routing/Router.php, line 255]
Code Context

is_subclass_of - [internal], line ??
Router::connect() - CORE/Cake/Routing/Router.php, line 255
include - APP/Config/routes.php, line 213
etc.

The problem is in is_subclass_of() so I presume that my app::uses() is
incorrect. Can anyone show me an example that works?

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: custom route classes in 2.x?

Tilen Majerle
because your PageSlugRoute has to be extended from CakeRoute :)
--
Lep pozdrav, Tilen Majerle



2012/2/21 lowpass <[hidden email]>
s_subclass_of

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: custom route classes in 2.x?

lowpass
On Mon, Feb 20, 2012 at 6:08 PM, Tilen Majerle <[hidden email]> wrote:
> because your PageSlugRoute has to be extended from CakeRoute :)

It is. I should have mentioned that.

class PageSlugRoute extends CakeRoute

I've been trying to debug how class loading is supposed to work. I
adjusted App::load()

public static function load($className) {
        if (!isset(self::$_classMap[$className])) {
                return false;
        }
       
        echo ": ${className} :";

I have to echo because debug() won't be available. I then added to
Router::connect()

if (isset($options['routeClass'])) {
        $routeClass = $options['routeClass'];
        debug($routeClass);

This gives me:

: Configure :: Cache :: FileEngine :: ErrorHandler :: Dispatcher ::
CakeRequest :: CakeResponse :: Inflector :: Router :: CakeRoute :
lib/Cake/Routing/Router.php (line 256)

PageSlugRoute

: PageSlugRoute :: Debugger :: Set :: String :

Warning (2): Unknown class passed as parameter
etc.

So, it seems to be properly loaded when it's needed, but I'm really
not sure where to go from here.

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: custom route classes in 2.x?

lowpass
I clued in to change it to:

App::uses('PageSlugRoute', 'routes');

But now I get a fatal error when PageSlugRoute imports the Page model:

Fatal error: Class 'Model' not found in
/var/www/vhosts/jcah/app/Model/AppModel.php on line 3

So it's no longer possible to instantiate a model inside a custom
route class? Is anyone doing this in 2.x?

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: custom route classes in 2.x?

Sam Sherlock
I have my custom routes working fine in 2.x

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

the class in Lib/Route


App::uses('Article', 'Model');
App::uses('CakeRoute', 'Routing/Route');
class ArticleRoute extends CakeRoute {
...
}

in AppModel.php I have

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

class AppModel extends Model {
...
}
 - S




On 21 February 2012 01:18, lowpass <[hidden email]> wrote:
I clued in to change it to:

App::uses('PageSlugRoute', 'routes');

But now I get a fatal error when PageSlugRoute imports the Page model:

Fatal error: Class 'Model' not found in
/var/www/vhosts/jcah/app/Model/AppModel.php on line 3

So it's no longer possible to instantiate a model inside a custom
route class? Is anyone doing this in 2.x?

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: custom route classes in 2.x?

lowpass
On Mon, Feb 20, 2012 at 8:57 PM, Sam Sherlock <[hidden email]> wrote:
>
> in AppModel.php I have
>
> App::uses('Model', 'Model');
>
> class AppModel extends Model {

By the shaking, jumping ghost of Jehosaphat! Yes, that did it. Seems
perfectly obvious now but I don't think I was going to see that any
time soon. Thanks!

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: custom route classes in 2.x?

Sam Sherlock
happy baking :)
 - S




On 21 February 2012 02:03, lowpass <[hidden email]> wrote:
On Mon, Feb 20, 2012 at 8:57 PM, Sam Sherlock <[hidden email]> wrote:
>
> in AppModel.php I have
>
> App::uses('Model', 'Model');
>
> class AppModel extends Model {

By the shaking, jumping ghost of Jehosaphat! Yes, that did it. Seems
perfectly obvious now but I don't think I was going to see that any
time soon. Thanks!

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Loading...