O'Reilly logo

CakePHP 2 Application Cookbook by Jorge González, James Watts

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Custom route class

Although the base routing system provided with CakePHP will cover almost all cases, there may be times when you need to handle things which are slightly more complex. For this reason, the framework provides the option to define a custom route class, which processes more complicated scenarios.

In this recipe, we'll create a custom route class to handle news headlines for given year and month.

Getting ready

For this recipe, we'll need to create a custom route class to use in our routing. Therefore, create a file named HeadlineRoute.php in app/Routing/Route/ with the following content:

<?php
App::uses('CakeRoute', 'Routing/Route');
App::uses('ClassRegistry', 'Utility');

class HeadlineRoute extends CakeRoute {
}

We'll then need some ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required