![]() |
How do I retrieve a uri segment in a hook? - 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: How do I retrieve a uri segment in a hook? (/showthread.php?tid=32917) Pages:
1
2
|
How do I retrieve a uri segment in a hook? - El Forum - 08-09-2010 [eluser]Salvatore Formisano[/eluser] As per title, since my other detailed post isn't being very popular.. ( http://ellislab.com/forums/viewthread/163604/ ) I guess I'll split the questions I have in order to accomplish what I'm trying to do ![]() In order to retrieve a uri segment in a controller normally all I have to do is $this->uri->segment(1) to get the first uri segment. How do I do it from a hook tough? How do I retrieve a uri segment in a hook? - El Forum - 08-09-2010 [eluser]WanWizard[/eluser] Tried Code: $CI =& get_instance(); How do I retrieve a uri segment in a hook? - El Forum - 08-09-2010 [eluser]Jelmer[/eluser] If your hook is pre-controller, before the Controller (and with it the CI_Base) has been instantiated, the get_instance() won't work. In that case you could try: Code: load_class('uri')->segment(1); // CI 1.7.2 How do I retrieve a uri segment in a hook? - El Forum - 08-09-2010 [eluser]Salvatore Formisano[/eluser] doesn't seem to be working (I receive a blank page) How do I retrieve a uri segment in a hook? - El Forum - 08-09-2010 [eluser]Jelmer[/eluser] Set error_reporting( E_ALL ); in your main index and if that doesn't give you the error add ini_set('display_errors', 'On'); just below it. How do I retrieve a uri segment in a hook? - El Forum - 08-09-2010 [eluser]Salvatore Formisano[/eluser] done, this is what I get Code: Fatal error: Cannot redeclare class CI_URI in /Users/macuser/Sites/sitename/system/libraries/URI.php on line 29 (I changed macuser and sitename for privacy, I obviously have the right stuff setup ![]() How do I retrieve a uri segment in a hook? - El Forum - 08-09-2010 [eluser]Salvatore Formisano[/eluser] Even this alone fails (just deleted the rest to make sure the mistake is here: Code: <? and in case this can be useful, here's the hook declaration: Code: $hook['pre_system'] = array( How do I retrieve a uri segment in a hook? - El Forum - 08-09-2010 [eluser]Jelmer[/eluser] Weird, it seems the load_class() function doesn't know the class was already loaded and tries to a second time when already loaded. Which causes your error. It might be an upper/lowercase issue: Code: load_class('URI')->segment(1); Or you could try something like this (because of the error I'm pretty sure it's already loaded): Code: $libs = is_loaded(); How do I retrieve a uri segment in a hook? - El Forum - 08-09-2010 [eluser]Salvatore Formisano[/eluser] Heh.. it gets even funnier ![]() Code: <? returns Code: Fatal error: Call to undefined function is_loaded() in /Users/rino/Sites/gerardopanariello/application/hooks/pick_language.php on line 63 How do I retrieve a uri segment in a hook? - El Forum - 08-09-2010 [eluser]Salvatore Formisano[/eluser] not sure if you noticed.. could this have anything to do with the fact that this hook is pre_system? |