1

I've this in my config/routes.php:

$route['music/artist/(:any)'] = "music/artist/index/$1";

I've an artist controller inside controller/music/ and index method.

So if I go to browser with domain.com/music/artist/michael then with the following line in controller I can get the data michael.

$this->uri->segment(3);

Please correct me if I'm wrong but here's the real question.

Now I want to have this on link.

domain.com/music/artist/michael/video/beat-it/

I want to have a video function inside the artist controller and inside I want to get the dynamic data, michael and beat-it.

So the routes config I've these:

$route['music/artist/(:any)'] = "music/artist/index/$1";
$route['music/artist/(:any)/video/(:any)'] = "music/artist/video/$1/$2";

If I go to the video link it seems it just hit the index function.

How can I make the video link work?

1 Answer 1

1

Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.

Switch the places of routes. Most specific routes need to be parsed first because (:any) placeholder would take anything there.

$route['music/artist/(:any)/video/(:any)'] = "music/artist/video/$1/$2";
$route['music/artist/(:any)'] = "music/artist/index/$1"; 

Reference.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.