CodeIgniter: How to get Controller, Action, URL information

前端 未结 11 1216
死守一世寂寞
死守一世寂寞 2020-12-07 09:21

I have these URLs:

  • http://backend.domain.com/system/setting/edit/12
  • http://backend.domain.com/product/edit/1

How to get controller nam

11条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-07 10:14

    Update

    The answer was added was in 2015 and the following methods are deprecated now

    $this->router->fetch_class();  in favour of  $this->router->class; 
    $this->router->fetch_method(); in favour of  $this->router->method;
    

    Hi you should use the following approach

    $this->router->fetch_class(); // class = controller
    $this->router->fetch_method(); // action
    

    for this purpose but for using this you need to extend your hook from the CI_Controller and it works like a charm, you should not use uri segments

提交回复
热议问题