다음 URL이 있습니다.
이 URL에서 컨트롤러 이름, 작업 이름을 얻는 방법. 저는 CodeIgniter 초보자입니다. 이 정보를 얻을 수있는 도우미 기능이 있습니까?
전의:
$params = helper_function( current_url() )
$params다음과 같이되는 곳
array (
'controller' => 'system/settings',
'action' => 'edit',
'...'=>'...'
)
다음 URL이 있습니다.
이 URL에서 컨트롤러 이름, 작업 이름을 얻는 방법. 저는 CodeIgniter 초보자입니다. 이 정보를 얻을 수있는 도우미 기능이 있습니까?
전의:
$params = helper_function( current_url() )
$params다음과 같이되는 곳
array (
'controller' => 'system/settings',
'action' => 'edit',
'...'=>'...'
)
답변:
URI 클래스를 사용할 수 있습니다 .
$this->uri->segment(n); // n=1 for controller, n=2 for method, etc
나는 또한 다음 작업을 들었지만 현재 테스트 할 수 없습니다.
$this->router->fetch_class();
$this->router->fetch_method();
URI 세그먼트를 사용하는 대신 다음을 수행해야합니다.
$this->router->fetch_class(); // class = controller
$this->router->fetch_method();
이렇게하면 라우팅 된 URL 뒤에 있거나 하위 도메인 등에있는 경우에도 항상 올바른 값을 사용하고 있음을 알 수 있습니다.
modules::run('module/controller/action'). 로드 된 페이지의 라우터 정보 만 보여줍니다. 이것을 극복 할 방법이 있습니까?
$this->router코드가 실행되는 클래스를 반환하지만 재정의로 마스킹 된 실제 라우터는 반환하지 않습니다. 두 가지 답변 모두 원하는 작업에 따라 매우 유용합니다.
$this->router->class되었으며 $this->router->method대신 사용되었습니다.
메소드는 더 이상 사용되지 않습니다.
$this->router->fetch_class();
$this->router->fetch_method();
대신 속성에 액세스 할 수 있습니다.
$this->router->class;
$this->router->method;
URI 라우팅 메소드 fetch_directory (), fetch_class (), fetch_method ()
속성
CI_Router::$directory을 사용CI_Router::$class하고CI_Router::$method공개되고 각각은fetch_*()더 이상 속성을 반환하기 위해 다른 작업을 수행하지 않습니다. 속성을 유지하는 것은 의미가 없습니다.그것들은 모두 내부의 문서화되지 않은 방법이지만 만일을 대비하여 이전 버전과의 호환성을 유지하기 위해 지금은 그것들을 사용하지 않기로 결정했습니다. 일부 사용자가이를 활용했다면 이제 대신 속성에 액세스 할 수 있습니다.
$this->router->directory; $this->router->class; $this->router->method;
또 다른 방법
$this->router->class
추가로
$this -> router -> fetch_module(); //Module Name if you are using HMVC Component
fetch_module()호출은 CI 2.1.2에서 작동하지 않습니다. /system/router.php 파일에서 찾을 수 없습니다.
최신 정보
답변은 2015 년에 추가되었으며 다음 방법은 현재 더 이상 사용되지 않습니다.
$this->router->fetch_class(); in favour of $this->router->class;
$this->router->fetch_method(); in favour of $this->router->method;
안녕하세요 다음 접근 방식을 사용해야합니다
$this->router->fetch_class(); // class = controller
$this->router->fetch_method(); // action
이 목적을 위해 그러나 이것을 사용하려면 후크를 확장해야 CI_Controller하며 매력처럼 작동하므로 uri 세그먼트를 사용해서는 안됩니다
컨트롤러 클래스가 어떤 기능도 작동하지 않습니다.
그래서 다음 스크립트를 사용하는 것이 좋습니다
global $argv;
if(is_array($argv)){
$action = $argv[1];
$method = $argv[2];
}else{
$request_uri = $_SERVER['REQUEST_URI'];
$pattern = "/.*?\/index\.php\/(.*?)\/(.*?)$/";
preg_match($pattern, $request_uri, $params);
$action = $params[1];
$method = $params[2];
}