Welcome Guest, Not a member yet? Register   Sign In
Determining Index v. Non-Index
#1

[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?
#2

[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"
#3

[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.
#4

[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.




Theme © iAndrew 2016 - Forum software by © MyBB