Welcome Guest, Not a member yet? Register   Sign In
how to always get first parameter after method name?
#1

[eluser]wolffc[/eluser]
I couldn't find an option in the URI class but is there way to always get the first parameter after the method name. I know I can add a parameter to the method and get it that way but every page will have the same first parameter. I also need to get this in a hook to set some session data.

/controller/method/1

/subfolder/controller/method/1

Can I do this.

Thanks for the help
#2

[eluser]Tom Schlick[/eluser]
why would you want to do this? im jw. what purpose could this serve
#3

[eluser]xwero[/eluser]
Code:
funcion first_parameter()
{
    $CI =& get_instance();
    if($CI->uri->total_rsegments() > 2) // check for more than controller/method segments
    {
       $first_parameter = $CI->uri->segment(3);
       // do whatever you want with it
    }
}
call this in the post_controller_constructor hook.
#4

[eluser]wolffc[/eluser]
[quote author="trs21219" date="1232776152"]why would you want to do this? im jw. what purpose could this serve[/quote]

Well, it's for work so i don't want to go into too much about why i am doing this. Basically the parameter is a id and all the pages in the site are rendered based on the id that is set. I want to store the current id in a session along with some other data associated with the id. In my hook I need to test when they switch ids so i can load new information into the session. I am wanting to limit database calls as much as possible. If there are better ways i would be happy to hear about them.
#5

[eluser]wolffc[/eluser]
[quote author="xwero" date="1232779572"]
Code:
funcion first_parameter()
{
    $CI =& get_instance();
    if($CI->uri->total_rsegments() > 2) // check for more than controller/method segments
    {
       $first_parameter = $CI->uri->segment(3);
       // do whatever you want with it
    }
}
call this in the post_controller_constructor hook.[/quote]

D'oh, I was using segment(3) instead of rsegment(3) Smile I don't even need a function test since i am making the method name required.




Theme © iAndrew 2016 - Forum software by © MyBB