を使用$this->router->fetch_class()
して、現在のコントローラー$this->router->fetch_method()
を取得し、必要に応じてメソッドも取得できます。
リンクしたYiiの例と同様に、次のようなことができます
$is_home = $this->router->fetch_class() === 'name_of_home_controller' ? true : false;
または方法も一致させる
$is_home = ($this->router->fetch_class() === 'name_of_home_controller' && $this->router->fetch_method() === 'name_of_home_method') ? true : false;
このように、ページの URL がhttp://yoursite.com/ (ホーム コントローラーとメソッドがデフォルトであると仮定)、http://yoursite.com/home_controller/、http://yoursite.com/something/thatであっても/routes/to/home/controller/など、そのコントローラーを呼び出している限り、$is_home を true に設定します。
編集:($this->router->fetch_class() === $this->router->default_controller)
ホームコントローラーを明示的に指定したくない場合や、デフォルトのコントローラーに設定されている場合にも使用できます。
CI v3 の更新: CI v3
$this->router->fetch_class()
で$this->router->fetch_method()
廃止されました。代わりに$this->router->class
andを使用してください。$this->router->method