Hi, in Cake 1.3 I had a custom route class set up which looked as follows:

/app/libs/routes/slug_route.php


<?php
>
>     class SlugRoute extends CakeRoute 
>     {
>         function parse($url) 
>         {
>             $params = parent::parse($url);
>             if (empty($params)) 
>             {
>                 return false;
>             }
>             
>             $slugs = Cache::read('dp_slugs');
>             if (empty($slugs) || !array_key_exists($params['slug'], 
> $slugs)) 
>             {
>                 App::import('Model', 'DynamicPage');
>                 $DynamicPage = new DynamicPage();
>                 $pages = $DynamicPage->find('all', array(
>                     'fields' => array('DynamicPage.url_slug'),
>                     'recursive' => -1
>                 ));
>                 $slugs = array_flip(Set::extract('/DynamicPage/url_slug', 
> $pages));
>                 Cache::write('dp_slugs', $slugs);
>             }
>             
>             if (isset($slugs[$params['slug']])) 
>             {
>                 return $params;
>             }
>             
>             return false;
>         }
>
>     }
>
>
> ?>
>

I've just set up a Cake 2 website and this just tells me:  

Route class not found, or route class is not a subclass of CakeRoute
>
> Error: An Internal Error Has Occurred.
>

 I'm trying to find an example of a custom route for url_slugs that works 
but I can't get it working. Any ideas what I need to update to make it 
work? Based on what I've been able to find, I've updated it so that now the 
class is in /app/Lib/Routing/Route/slug_route.php and looks like this:

<?php
> /**
>  * Deal with URL Slugs
>  */
> App::uses('DynamicPage', 'Model');
> App::uses('CakeRoute', 'Routing/Route');
>
> class CategorySlugRoute extends CakeRoute {
>
>     /**
>      * Parse the URL
>      * @param string $url
>      * @return boolean
>      */
>     function parse($url) {
>         $params = parent::parse($url);
>         if (empty($params)) {
>             return false;
>         }
>
>         // See if slugs are cached
>         $slugs = Cache::read('dp_slugs');
>         if (!$slugs) {
>             // Get all slugs
>             $DynamicPage = new DynamicPage();
>             $slugs = $DynamicPage->find('list', array(
>                 'fields' => array('DynamicPage.url_slug'),
>                 'recursive' => -1
>             ));
>
>             Cache::write('dp_slugs', $slugs);
>         }
>
>         // Reverse slugs for easy comparison
>         $slugs = array_flip($slugs);
>
>         // See if dynamic pages have been passed
>         if (!empty($params['pass'])) {
>             $params['slug'] .= '/' . implode('/', $params['pass']);
>         }
>
>         // Match passed slug with Category slugs
>         if (isset($slugs[$params['slug']])) {
>             return $params;
>         }
>
>         return FALSE;
>     }
> }
>

in /app/config/routes.php I have this at the end of the file:

App::uses('SlugRoute', 'Routing/Route');
>     Router::connect('/:slug', array('controller' => 'dynamic_pages', 
> 'action' => 'view'), array('routeClass' => 'SlugRoute'));


But I still have the error. Any ideas would be greatly appreciated

Thanks!

Patrick

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to