$route[':any'] issue |
[eluser]Randy Casburn[/eluser]
That's one way to look at it. I suppose the other way to look at it is that CI is very flexible in it's approach, but you're not flexible in your design. Either way one of you has to budge a little. You can make CI do what you want, you just have to open you mind a little to make it bend to your will. You'll then see how really flexible it is :-) Best Regards, Randy
[eluser]Randy Casburn[/eluser]
Hi EEssam, Just for fun, I thought I would put something together to demonstrate how to do this. I'm certain there are 10 ways, but this is one. The design concept is simply to have a somewhat static facing web that would be fantastic for SEO purposes. The true application that resides behind this static site, built with CI, of-course, would never be built this way but would be discovered because of the great SEO attributes the single-word-from-root web page name provides. Disclaimer: Put some error checking in here somewhere! Controller: Code: class Home extends Controller Model function from file Getmystuff.php Code: function getPageDataFromDB($page) For the views: Note I'm passing $this->pageData array. The pageData array is simply constructed from the DB rows returned by the model. Use the variable representations of those rows within your views to show the content in your view templates. I hope this more thoroughly answers your question. Most importantly, shows you how awsome CI can really be once you understand it's flexibility. So here is one 'realization' of use CI and construct your URLs with the page name right after the FQDN thus: http://mydomainname.com/mypage or http://mydomainname.com/mypage.html Regards, Randy
[eluser]Pascal Kriete[/eluser]
It can be done - without routes. In router.php, the function _validate_request checks if the controller exists. Now at the very bottom of that function you have this line: Code: show_404($segments[0]); Change that to read (override the function, don't edit the core file): Code: return array('welcome', 'show_page', $segments[0]); So if the controller doesn't exist, it will call the welcome controller show_page function and pass the name of the page in as an argument. Make sure to throw a 404 if the page doesn't exist though.
[eluser]Randy Casburn[/eluser]
When I looked at router.php and thought about overriding it, the first thing I thought of was how I personally have a problem with loosing track of mods that change the nature of the config files. I've tried to stop overriding the core because I keep forgetting what I have rendered irrelevant. In this case, I'm almost certain we would render the 'default_controller' config setting moot. Later on (months, weeks, years, etc.), I would likely be the fool trying to figure out why that setting just wasn't working ;-)
[eluser]Pascal Kriete[/eluser]
At the top of my core extensions I try to list the changes I make. Also, this does not override the default_controller setting (replacing a 404 statement, remember). I do use this occasionally to catch silly misspellings and redirect them to the homepage. Misspelled functions are another thing, but most people don't type that much .
[eluser]EEssam[/eluser]
"override the function, don’t edit the core file" how can I do that? :S Thanks.
[eluser]Randy Casburn[/eluser]
When you create a class that extends another class (a super class) you override the the methods of the super class by naming your methods with the same name of the super class' methods. If you want to retain the functionality of the super class' method, you'll need to duplicate that functionality in your method because the super class' method will no longer be available to you. Make sense? (edited to clean up the terminology a little [method vs. function] )
[eluser]Steve Wright[/eluser]
I am doing a similar thing in one of my applications using... $route['(:any)'] = "display/index/$1"; The index function of the display controller accepts one argument which is the page name in the database. If the query returns no matching page, it serves a 404. The trick is that routes to any other controllers/functions must be listed BEFORE the catch-all route shown above.
[eluser]Jamie Rumbelow[/eluser]
If you are using .htaccess to rewrite a file, try setting your URI_PROTOCOL in config.php to REQUEST_URI. That might work! |
Welcome Guest, Not a member yet? Register Sign In |