Controller not found -> Use this controller |
[eluser]Chicken's Egg[/eluser]
CodeIgniter can load a controller by default. After a plain installation that is the welcome.php controller. I searched the user guide, but I didn't find an answer on the following question. Is it possible to get something like. - Of no controller is given in the uri -> use default controller. (for example welcome.php) - If a controller is specified -> use specified controller. (for example: weblog, shop, forum) - If that specified controller doesn't exist / is not found -> use this other by CI specified controller. (for example text.php) So: www.mysite.com | Uses welcome.php www.mysite.com/blog/ | Use blog.php www.mysite.com/mypage/ | Use text.php Goal: I would like to have a possibility to add some text pages to my website aswell, usinng CI, but without telling CI that they can be viewed using the controller text. I have been thinking about a solution too. I could create a route using regular expression and check if the asked controller exists. But: I don't know if all regular expression functions can be used and it is hard coded. I would rather prefer a more flexible solution.
[eluser]Chicken's Egg[/eluser]
But that tutorial is about getting a default view for the controller method. Or did I miss the point?
[eluser]xwero[/eluser]
That is one example of customization. For the thing you want you need to change Code: if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) Code: $class = $RTR->fetch_class(); Code: $class = $RTR->fetch_class(); The rest of your requested behavior is already in CI so that doesn't need to be changed.
[eluser]Chicken's Egg[/eluser]
So may be even this would work: Code: if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) Well, I'm gonna play a little bit more with it. This sounds a great opportunity. Thank you very much for your help.
[eluser]xwero[/eluser]
The class variable is used further in the script so somewhere you need to give it a value. I think you want to add the string text but you forgot to put it inside quotes |
Welcome Guest, Not a member yet? Register Sign In |