drcomwc134525 2016-01-23 09:51
浏览 54

codeigniter如何设置没有段的路由,也没有段的路由

I am stuck with route. Here is my route.

$route['login_register'] = 'welcome/login_register';

First time I don't want to pass any extra segment.
After Login fail,I want to redirect login_register function with failure argument in URL.
If I don't use /(:any),I can't access.

$this->uri->segment(2);

If i use /(:any),it is giving me error when first time redirecting.

$route['login_register/(:any)'] = 'welcome/login_register';
  • 写回答

1条回答 默认 最新

  • dstm2014 2016-01-23 10:04
    关注

    you cant do login_register and login_register/(:any) with same route. You can do one more thing with this.

    Use one route

    $route['login_register'] = 'welcome/login_register';
    

    then inside function

    public function login_register($value)
    {
        if (empty($value)) { # first method
            echo "No argument passing";
        }
        else{ # second method
            echo "argument is there";;
        }
    }
    

    So when use passing data to controller send with / key. Ex:

    <a href="<?php echo base_url() ?>login_register"> This print first method</a>
    <a href="<?php echo base_url() ?>login_register/25"> This print second method</a>
    
    评论

报告相同问题?