如何使用 uri_string() codeigniter 获得 URL?

How to get the a URL using uri_string() codeigniter?

我想实现和登录身份验证功能,当像这样加载控制器时检查每个 URL?

 //get the current URL
        $url = $this->uri->uri_string();

     if(  ($this->ion_auth->logged_in()== false )&& 
          !( in_array($url,$public_allowed_urls) ) ) {
                 redirect('users/login');
            }

我也试过从 AUTO 改变这个 $配置['uri_protocol'] = 'REQUEST_URI';

请问你是怎么做到的..我用的是最新的CI?

你知道吗..你会花时间为 URI_STRING 事情找工作?

但是,我已经为大家做了一个解决方案...

首先获取动作和控制器

喜欢"Weclome/Home","users/login",'sell/sell','sell/index','sell/','/'

   //get the current URL
    $controller= $this->uri->segment(1); // controller
    $action = $this->uri->segment(2); // action
    $url = $controller . '/' . $action; 
    //'this returns / sometimes and  also  like sell/ returned'


 if(  ($this->ion_auth->logged_in()== false )&& (in_array($url,$public_allowed_urls) ) )
 {                  
  redirect('users/login');
  }

做人!

已编辑:

$this->uri->segment(1); 不能是控制器名称所有 time.To 获取控制器名称使用 $this->router->class 和方法 $this->router->method