Codeigniter Routes regex - using dashes in controller/method names

前端 未结 9 1223
小鲜肉
小鲜肉 2020-11-29 01:32

I\'m looking for a one line route to route dashed controller and method names to the actual underscored controller and method names.

For example the URL



        
9条回答
  •  渐次进展
    2020-11-29 01:40

    Overriding the Router class is a nice approach, there is also a way of replacing - with _ by registering a "pre-system" hook.

    First create the hook by adding these lines to your ‘config/hooks.php’ file:

    $hook['pre_system'] = array(
        'class'    => '',
        'function' => 'prettyurls',
        'filename' => 'myhooks.php',
        'filepath' => 'hooks',
        'params'   => array()
    ); 
    

    Now create a ‘myhooks.php’ file within the ‘application/hooks’ folder and add this function (don’t forget to open a PHP tag if this is the first hook):

    You will probably need to edit your ‘config/config.php’ file to enable hooks (around line 91 for me):

    $config['enable_hooks'] = TRUE; 
    

    This answer is ripped from http://codeigniter.com/forums/viewthread/124396/#644012

提交回复
热议问题