• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[solved - thanks!] $this->uri->rsegment(x) in a hook?

#1
[eluser]Tim Skoch[/eluser]
I'm trying to use the URI class in a pre-controller hook, but whenever I do, I get the following PHP error:

Fatal error: Using $this when not in object context in /path/to/my/ci/installation/system/application/hooks/login.php on line 3

My call from within the hook is as follows:
echo($this->uri->rsegment(1));

(bad form, I know, echoing output before headers are sent. But I'm just troubleshooting right now...)

All I need to obtain is the first segment of the URI after it has been routed.

#2
[eluser]wiredesignz[/eluser]
Code:
$URI =& load_class('URI');

#3
[eluser]xwero[/eluser]
To get the segments i suggest you use a post_controller_constructor hook because the super object isn't defined yet when executing pre_controller hooks. You can get the segments but then you have to use this
Code:
$URI =& load_class('URI');
echo $URI->rsegment(1);
The core classes are loaded but they are just a bunch of classes before the controller is loaded.

edit : wiredesignz beat me Smile

#4
[eluser]Tim Skoch[/eluser]
Thanks guys! Your suggestion worked great. I've outlined what I was working on in the following post, hoping to attract some constructive criticism.

Uber-simple login script...


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.