[Solar-talk] _getActionHref

Rodrigo Moraes rodrigo.moraes at gmail.com
Tue Aug 7 16:16:51 CDT 2007


On 8/7/07, Jeff Surgeson wrote:
> Thats great however not quite there yet, still trying to get the router and
> the helper to work with my apps.

Controller helpers are really not necessary and I'd suggest you to
keep away from them for simplicity. Below I explain basic setup for
the router controller.

> I have always tried to stay as close to
> Solar layout and structure as possible as I am not as versatile as you guys
> when it comes to making major changes. :-(

Me too, and I am very close to Solar, really I am. The router
controller is an extended Solar_Controller_Front and really, there is
*one* thing you need to work with routes and Solar 0.28: add the
method setFrontController() in your app or page controller. This
method is currently on Solar_Controller_Pager/SVN and it allows apps
to "talk" with the front controller, like we do to assemble URI's for
routes or to get the current active route and route parameter values.

So basically, you only need setFrontController() plus the related
$_front property, as in Solar_Controller_Pager/SVN.

Then you can start playing with routes defined in
Tipos_Controller_Router's config or using the available methods to
addRoutes:

Defining routes in config is so clean and easy! See what I do in config.php:

<?php
    $config['Tipos_Controller_Router'] = array(
        'classes' => 'Tipos_App',
        'default' => 'news',
        'routing' => array(),
        'routes'  => Solar::run(dirname(__FILE__) . '/routes.php'),
    );
?>

Voilá! I've set a separated config file for the routes, routes.php.
Here's an example of the file with a generic route for modules:

<?php
$routes = array();

// Generic module route.
$routes['module'] = array(
    'route'    => ':module/:controller/:action/*',
    'defaults' => array(
        'module'     => 'news',
        'controller' => 'base',
        'action'     => 'index',
    ),
    'route_class' => 'Tipos_Controller_Route_Route',
);

return routes;
?>

It allows you to divide apps in 'modules' / subdirs, organizing things
better. But there is much more to do with routes; you need to start
playing with them to see the power of named parameters, required
parameters, regex based routes, abstracted uri's...

ZF's RewriteRouter manual can give you a better idea of how routes
work. Although the API is not exactly the same, I think it is easy to
find the equivalents in Tipos_Controller_Router. I'd say that setting
routes and starting with the controller is even a bit easier than in
ZF, because routes definitions integrates well with Solar config
system. And if you don't set any routes at all, the controller will
fallback to Solar_Controller_Front, making the router controller
almost irresistible. Hehe. ;)

Let me know if you have any doubts.

cheers,
rodrigo



More information about the Solar-talk mailing list