CodeIgniter Forums
parse url, class=active - 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: parse url, class=active (/showthread.php?tid=37813)



parse url, class=active - El Forum - 01-21-2011

[eluser]benfike[/eluser]
Hi!

Code:
<?php $page = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); ?>
                        <? $page_exploded = explode('/', $page, 2);
                        if (count($page_exploded) == 2){
                            $address = $page_exploded[0];
                            $controller = $page_exploded[1];
                        }
                        ?>
                            <li &lt;?php if ($controller == 'admin/overview') { ?&gt;class="active"&lt;?php } ?&gt;><a class="nav-icon icon-house" href="&lt;?=base_url()?&gt;admin/overview">Áttekintés</a></li>

So if $controller = admin/overview then set li class="active"....

It works fine, but it dont work when there is a function for overview controller, example: add, modify etc.

what can I do?

or there is a easiest way to make something like this?

Sorry for my english;


parse url, class=active - El Forum - 01-21-2011

[eluser]Victor Michnowicz[/eluser]
A better way to get the current class and method:

Code:
$this->router->class;
$this->router->method;



parse url, class=active - El Forum - 01-23-2011

[eluser]benfike[/eluser]
thanks Tongue