简体   繁体   中英

How to check if Controller already exists when already configured route using Codeigniter?

On my website, I am loading the content dynamically from database like this

e.g mysite.com/about-us   

for this, there is an enrtry in database, so it will load the content for 'about-us' & print it using "page" controller only.

for this what I have done is, I have added below configuration in routes.php

$route[':any'] = "page";

but lets say if I already have controller named "about-us" and I want to load that & not the one from database, how can I do that?

A smooth solution would be to use the error/missing_page controller and point it in the config/routes.php .

Then it would automaticly pick all existing controllers first, and then that controller.

You can also call show_404() if you don't find a record in the database.

This allows you to create new controllers without having to point all of them in the route file.

Read about 404 override here

you need to add this

$route['about-us'] = "aboutus";
$route['about-us/(:any)'] = "aboutus/$1";

before

$route[':any'] = "page";

as the CI route is not greedy, it will not check for the page controller after it finds the about-us controller.

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