CodeIgniter Forums
Determining Index v. Non-Index - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Determining Index v. Non-Index (/showthread.php?tid=29688)



Determining Index v. Non-Index - El Forum - 04-18-2010

[eluser]netricate[/eluser]
I'm wondering if there is a more succinct way of determining if I am about the fire the index method than I am using. Currently, I have a couple checks in the class declarations that I don't want to fire if the index method is being called.

Code:
class A extends Controller {
    
    function A()
    {
        parent::Controller();
        $this->load->helper('url');
        
        if(!in_array($this->uri->uri_string(),array('/a','/a/')))  //check to make sure this is NOT the index page
        {
            //do things
        }
    }
}

Any suggestions?


Determining Index v. Non-Index - El Forum - 04-18-2010

[eluser]netricate[/eluser]
I'm currently trying this one, I think it's better, but has one flaw
Code:
if($this->uri->segment(2)) //would return false if this is just index, but doesn't account for "url/a/index"



Determining Index v. Non-Index - El Forum - 04-18-2010

[eluser]netricate[/eluser]
I played with this above a little more and it seems to work for all cases (http://www.myurl.com/a/index just redirects to /a). I'm still interesting in finding out if anyone has a better/different way of doing it, but this works for now.


Determining Index v. Non-Index - El Forum - 04-18-2010

[eluser]richthegeek[/eluser]
Try $this->uri->rsegment if it's still giving issues, or some of the router methods/properties. You should be able to directly access the called method name from that.