简体   繁体   中英

How to fix CodeIgniter routes

I am new in framework please help to solve this. I am working in CodeIgniter. I want to have clean URLs like this: example.com/index.php/6/title

index.php/6 is a post ID and title is a Page title. I want to get data by post ID.

Controller function:

public function watch(){
            echo id;

        }

How to get this clean URL using routes. I am trying this route but it's not working:

$route['(:num)/(:any)'] = 'front_controller/watch/';

Try this for routing to watch() function in Front_controller with 2 parameters id and title

$route['(:num)/(:any)'] = 'front_controller/watch/$1/$2';

Also you should accept 2 paramets in your controllers function too as :

function watch($id,$title)
{
    echo $id;
    echo $title;
}

Let me know in case of any queries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM