I have a method in a codeigniter controller that is sometimes called via a URL and sometimes called internally from another controller method. When I call it internally, I pass an array of arguments. Simplified version of the method:
(inside the controller)
function get_details($args='') {
if (isset($args['first_name']))
{
$first_name = $args['first_name'];
}
else
{
$first_name = $this->uri->segment(3);
}
... do some other stuff ...
}
The method is called either:
<domain>/<controller>/get_details/abcd/efgh
or from another controller function:
$this->get_details(array('first_name'=>'abcd', 'last_name'=>'efgh'));
I expected that when the method is called via url, isset ($ args ['first_name']) will be false, however it seems that the argument called in this way is. I tried to print a couple of things, and here is what I got:
print_r($args) ----> abcd
echo($args['first_name']) ----> a
echo($args['whatever_index_I_use']) ----> a
It seems like the third url parameter is being passed to the method (using codeigniter?), But cannot decide why the array indices seem to be set, all I can think of is that php will convert the string to int, so $args['whatever_index_I_use'], becomes $args[0]??
, - codeigniter php.
, , .
.