Search code examples
routeskohanakohana-3

How To Add Dash Between Controllers Name In Kohana?


I'm working on authorization module for Kohana 3.1. In my module's init.php...

Route::set(

    'a11n',
    '<controller>',
    array(
        'controller' => 'signIn|signOut|signUp'
    )

);

I'm not 100% sure how use to Kohana's routing mechanism, but with this I'm trying to achieve that user can type "signIn", "signOut" or "signUp" to run controllers from my module. You see, I want have "portable" authorization system... so I can simply "copy-paste" right directory, enable the module and my site have authorization.

Keep in mind, with this route I don't want to anyhow change behavior of default routes. I don't know how correct my code is... but it works! I tested and I can get the same effect without using 3rd parameter too. What do I achieve with it now?

And now the question... How can I somehow set routes from module that by typing "sign-in" user run module "Controller_SignIn"?


Solution

  • You should use the routes to do that, something like this:

    Route::set('SignIn', '/sign-in(/<action>)',
            array(
                'action' => 'index|action1',
                )
            )
            ->defaults(
                    array(
                        'controller' => 'SignIn',
                        'action' => 'index',
                        )
                    );
    
    Route::set('SignOut', '/sign-out(/<action>)',
            array(
                'action' => 'index|action1',
                )
            )->defaults(
                    array(
                        'controller' => 'SignOut',
                        'action' => 'index',
                        )
                    );
    

    or

    Route::set('SignIn', '/sign-in/',
            array()
            )
            ->defaults(
                    array(
                        'controller' => 'user',
                        'action' => 'login',
                        )
                    );
    
    Route::set('SignOut', '/sign-out/)',
            array()
            )->defaults(
                    array(
                        'controller' => 'user',
                        'action' => 'logout',
                        )
                    );