What is the best practice to name the default controller and default model? |
[eluser]term25[/eluser]
[quote author="CroNiX" date="1339700565"]The default_controllers name doesn't show up in the url. It executes when there is nothing in the url, aka the site homepage. So it shouldn't really matter what it's called (it's using a route, which maps the url to something other than what is in the url which is normally presumed to be the controller). www.yoursite.com/ = default_controller www.yoursite.com/something = Specific CI controller Yes you can access your default controller via url, like www.yoursite.com/default_controller, but that shouldn't matter as you shouldn't be generating links to your homepage by using the name of the default_controller in the url, you'd just link to www.yoursite.com. You can also check $this->uri->segment(1) to see if it is the name of the default_controller (meaning accessed in the url via the name of the default_controller) and reject it so that you can only access it by it's routed name, if that is a concern. I generally have a setup similar to nagata, where I have a "pages" controller. Code: $route['default_controller'] = 'pages'; The index method of the pages controller is what displays the homepage when the default_controller is called. There is also a "view" method which accepts a page name as a parameter, which I use to pass certain pages to from my routes. This is to generate static pages, like 'about-us', 'contact-us', etc., where the pages are more general, less complex, don't take parameters, etc. So if the url is www.yoursite.com/about-us, it sends 'about-us' to the view method of the pages controller and displays that static page using the url-friendly version, rather than www.mysite.com/pages/view/about-us.[/quote] Thanks for the explanation. Maybe I will also chose "pages". |
Welcome Guest, Not a member yet? Register Sign In |