![]() |
Can't use $this->uri->segment in if check... - 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: Can't use $this->uri->segment in if check... (/showthread.php?tid=9258) |
Can't use $this->uri->segment in if check... - El Forum - 06-18-2008 [eluser]Bramme[/eluser] Code: $section = isset($this->uri->segment(2)) ? $this->uri->segment(2) : 'overview_tutorials'; I'll try to explain what I need, maybe you guys have got some other idea that could solve my problem: I'm porting an existing backend to CI, his current backend has got a shitload of links in the navigation, so I want to reduce this and group them by their function. Each group has its subnav, directing to their controllers, if you click on one of the main nav links, you simply get taken to the first controller of the group... At the moment I do this like this in my controller constructor: Code: $tutorial_array = array('overview_tutorials' => 'Overview', 'new_tutorial' => 'New tutorial', 'categories' => 'Categories', 'ranks' => 'Ranks'); and my HTML looks like this Code: <ul id="nav"> Any ideas? Thanks a bunch! Can't use $this->uri->segment in if check... - El Forum - 06-18-2008 [eluser]nevercraft[/eluser] This will work: Code: $section = $this->uri->segment(2, 'overview_tutorials'); The second parameter of the segment() function is a default value to return if the segment you're looking for doesn't exist. For sessions you could do something like: Code: $var = ($this->session->userdata('varname') != FALSE ? $this->session->userdata('varname') : 'default value'); Can't use $this->uri->segment in if check... - El Forum - 06-19-2008 [eluser]Bramme[/eluser] Oh! Thanks! This is what happens when I start coding at 2am, I forget to check the user guide and just start posting. Thanks! |