How do I pass parameters to a controller\'s index() function?

Answer

The obvious problem is that a second parameter on the URL will be interpreted as the method name.

Short answer - use a URL like this: /controller/index/param1/param2

Long answer - using _remap() you can work some magic. This code is supplied courtesy of Colin Williams

function _remap ( $method ) {
$param_offset = 2;

// Default to index
if ( ! method_exists($this, $method))
{
// We need one more param
$param_offset = 1;
$method = 'index';
}

// Since all we get is $method, load up everything else in the URI
$params = array_slice($this->uri->rsegment_array(), $param_offset);

// Call the determined method with all params
call_user_func_array(array($this, $method), $params);
}

All CODEIGNITER Questions

Ask your interview questions on codeigniter

Write Your comment or Questions if you want the answers on codeigniter from codeigniter Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---