CodeIgniter Forums
need dynamic function name in controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: need dynamic function name in controller (/showthread.php?tid=61912)



need dynamic function name in controller - Gshankar - 05-30-2015

Hi,

www.domain.com/cars/hyundai/grandi10

In this one cars is a controller and remaining parameter is dynamic.so how to write a controller for this..


RE: need dynamic function name in controller - includebeer - 05-30-2015

PHP Code:
class Cars extends CI_Controller
{
 
   public function hyundai($car_model)
 
   {
 
       // $car_model contains "grandi10"
 
   }


Read this for more info:
http://www.codeigniter.com/userguide3/general/controllers.html#passing-uri-segments-to-your-methods


RE: need dynamic function name in controller - mwhitney - 06-01-2015

This may also be useful:
http://www.codeigniter.com/user_guide/general/controllers.html#remapping-method-calls

PHP Code:
public function _remap($method$params = array())
{
    
$carMake $this->getMake($method);
    
$carModel = empty($params) ? '' $this->getModel($params);
    
    
// do something now that you have the make and model