remapping

#1
[eluser]tzi0[/eluser]
Hi all
i have a _remap() function in my Admin controller:

Code:
function _remap($method)
    {
        if ($this->session->userdata("user_id"))
        {
            $this->$method();
        } else  
        {
            $this->index();
        }
    }

ok. now, if user requested a method with parameter, parameter doesnt pass:
Code:
function editcontent($id="none")
    {
        echo $id;
        if (is_numeric($id))
        { ... }
                ...
        }
$id always is "none". Why that? Have i to write something else in my _remap() function?

#2
[eluser]WanWizard[/eluser]
That is quite obvious.

Your editcontent() method is called from _remap() using '$this->$method()', so without parameters.
So either pass it in your call, or have your method determine the id itself.

Where did you expect this id would magically come from?

#3
[eluser]Clooner[/eluser]
You should call your function using call_user_func_array and pass func_get_args for arguments! Your code doesn't pass through any arguments and logically it always will be none!

#4
[eluser]tzi0[/eluser]
I thought $method is passed with parameters already ...
How to determine a requested parameter in my _remap() func? Through uri?

#5
[eluser]tzi0[/eluser]
[quote author="Jeroen Schaftenaar" date="1283180952"]You should call your function using call_user_func_array and pass func_get_args for arguments! Your code doesn't pass through any arguments and logically it always will be none![/quote]
Code:
function _remap($method)
        {
            if ($this->session->userdata("user_id"))
            {
                var_dump (func_get_args());
                $this->$method();
            } else
            {
                $this->index();
            }
        }
it says that i have one arg only - my method's name, but without id (

#6
[eluser]Clooner[/eluser]
[quote author="tzi0" date="1283182265"][quote author="Jeroen Schaftenaar" date="1283180952"]You should call your function using call_user_func_array and pass func_get_args for arguments! Your code doesn't pass through any arguments and logically it always will be none![/quote]
Code:
function _remap($method)
        {
            if ($this->session->userdata("user_id"))
            {
                var_dump (func_get_args());
                $this->$method();
            } else
            {
                $this->index();
            }
        }
it says that i have one arg only - my method's name, but without id ([/quote]

Why not try and read the documentation of the func_get_args on php.net? It means there are no arguments passed to the _remap method!

Either make sure that happens or simply pass the uri segment array as argument.

#7
[eluser]tzi0[/eluser]
Already. Thanks guys. Done by passing uri segment to my function.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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