Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <code>$this-&gt;router-&gt;fetch_class()</code> to get the current controller and <code>$this-&gt;router-&gt;fetch_method()</code> to get the method too if needed.</p> <p>So similar to the Yii example you linked to, you could do something like</p> <pre><code>$is_home = $this-&gt;router-&gt;fetch_class() === 'name_of_home_controller' ? true : false; </code></pre> <p>Or to match method too</p> <pre><code>$is_home = ($this-&gt;router-&gt;fetch_class() === 'name_of_home_controller' &amp;&amp; $this-&gt;router-&gt;fetch_method() === 'name_of_home_method') ? true : false; </code></pre> <p>This way even if the page url is <a href="http://yoursite.com/" rel="nofollow noreferrer">http://yoursite.com/</a> (assuming the home controller+method is the default), <a href="http://yoursite.com/home_controller/" rel="nofollow noreferrer">http://yoursite.com/home_controller/</a>, <a href="http://yoursite.com/something/that/routes/to/home/controller/" rel="nofollow noreferrer">http://yoursite.com/something/that/routes/to/home/controller/</a>, etc, as long as it's calling that controller, it'll set $is_home to true.</p> <p>Edit: Also you can use <code>($this-&gt;router-&gt;fetch_class() === $this-&gt;router-&gt;default_controller)</code> if you don't want to explicitly state the home controller and it's set to the default controller.</p> <p>Update for CI v3:<br> <code>$this-&gt;router-&gt;fetch_class()</code> and <code>$this-&gt;router-&gt;fetch_method()</code> were deprecated in CI v3. Use <code>$this-&gt;router-&gt;class</code> and <code>$this-&gt;router-&gt;method</code> instead.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload