Reputation: 5792
I migrated from Codeigniter 2 to 3. I have controller files in default controller directory as well as inside sub-directory called content and indexes. Current routes.php
file looks like this:
$controller_dir = opendir(APPPATH."controllers");
while (($file = readdir($controller_dir)) !== false) {
if (substr($file, -4) == ".php" ) {
$route[substr($file, 0, -4)."(.*)"] = substr($file, 0, -4)."$1";
} else if (substr($file, -5) == ".php/") {
$route[substr($file, 0, -5)."(.*)"] = substr($file, 0, -5)."$1";
}
}
$route['reviews'] = 'content/reviews/index/profile/$1';
$route['money/(:any)'] = 'indexes/money/index/$1';
$route['faq/do-i-need-to-signup'] = 'faq/question_answer';
$route['(:any)'] = 'index/profile/$1';
index/profile/$1
has logic to check username in database. I am using it as www.example.com/robert where robert is dynamic name (consider it as referal name). It was working in CI 2. But, in CI 3 getting 404 error with same code.
What am I missing here? Please ask me if question is not clear.
Upvotes: 1
Views: 1064
Reputation: 176
Now you need specify in route that it will be taking more parameters in query parts. Try this:
$route['reviews/(:any)'] = 'content/reviews/index/profile/$1';
this should solve the 404 error. You will be able to access it like: http://localhost/reviews/robert
If you want to pass more parameter just specify in route and you it $number
.
E.g.:
$route['reviews/(:any)/(:any)'] = 'content/reviews/index/profile/$1/$2';
Upvotes: 2