Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass argument in index function of controller

I have a controller name 'abc'

Now, I define a index function in it.

Now as i go to www.example.com/abc/ or www.example.com/abc/index i can see my page appearing.

Now when i pass argument in that index function i would have to call it as:

 www.example.com/abc/index/argument

So, How can i call my argument as

 www.example.com/abc/argument

without treating this 'argument' as public function ?

like image 310
Rahul Avatar asked Dec 14 '25 12:12

Rahul


2 Answers

you can add routing for it in your routes.php file, like:

$route['abc/(:any)'] = 'abc/index/$1';

doing this will route your url www.example.com/abc/argument to www.example.com/abc/index/argument

like image 195
Sudhir Bastakoti Avatar answered Dec 17 '25 03:12

Sudhir Bastakoti


Are you looking for remapping ?

public function _remap($method, $params = array())
{
    if (method_exists($this, $method))
    {
       return call_user_func_array(array($this, $method), $params);
    } 
    else 
    {
       return $this->index($method);
    }
    show_404();
}
like image 29
Ahmad Suhendri Avatar answered Dec 17 '25 02:12

Ahmad Suhendri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!