![]() |
What is the best practice to name the default controller and default model? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: What is the best practice to name the default controller and default model? (/showthread.php?tid=52526) Pages:
1
2
|
What is the best practice to name the default controller and default model? - El Forum - 06-14-2012 [eluser]term25[/eluser] I mean the one that is responsible to load your frontpage(homepage, landingpage etc.) Do you call this controller main.php or site.php? Or frontpage.php or home.php or something else? E.g. for the default model I am using this name: app_model.php Is there any convention? How do you call yours? What is the best practice to name the default controller and default model? - El Forum - 06-14-2012 [eluser]nagata[/eluser] firstly if I got you right, you want to know how to make index.php load some default controller, if so then its called 'default_controller', this mighty beast can hunt be huntdown usualy in routes.php in config folder, if you succed to find one such then it should usualy look like $route['default_controller'] = 'welcome'; ofcourse if you got clean CI install, if you failed to find this mighty beast, just create one, copy below $route['default_controller'] = 'home_controler/home_function'; but if seriusly, go and read more about CI URI Routing in User's Guide http://ellislab.com/codeigniter/user-guide/general/routing.html What is the best practice to name the default controller and default model? - El Forum - 06-14-2012 [eluser]PhilTem[/eluser] I don't think that was what @term25 was referring to ![]() He wanted to know what everybody in here has set up for Code: $config['default_controller'] = "what_do_you_have_here"; For me there is no straight answer, since my default_controller sometimes refers to 'display' (like for a static page display controller) or to 'welcome' or 'dashboard' depending on what application I'm working on. However, sometimes it's also set to 'bootstrap' since I do some custom bootstraping/routing and controller instantiation ![]() Anyway, most common for default_controller is 'display' What is the best practice to name the default controller and default model? - El Forum - 06-14-2012 [eluser]nagata[/eluser] in that case mine is Code: $route['default_controller'] = 'pages/view/Home'; What is the best practice to name the default controller and default model? - El Forum - 06-14-2012 [eluser]TWP Marketing[/eluser] Just a suggestion on naming; the use of "home" as a controller name is not a good idea for SEO purposes, unless you website just happens to be about "homes". Pick a name that relates to your site so the search engines will recognize that it relates to your content. Also pick a name, other than "home", for the first item in your main menu, again because the engines will downgrade your rank if it doesn't relate to page content. What is the best practice to name the default controller and default model? - El Forum - 06-14-2012 [eluser]CroNiX[/eluser] 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. What is the best practice to name the default controller and default model? - El Forum - 06-14-2012 [eluser]term25[/eluser] [quote author="TWP Marketing" date="1339699442"]Just a suggestion on naming; the use of "home" as a controller name is not a good idea for SEO purposes, unless you website just happens to be about "homes". Pick a name that relates to your site so the search engines will recognize that it relates to your content. Also pick a name, other than "home", for the first item in your main menu, again because the engines will downgrade your rank if it doesn't relate to page content. [/quote] Google's (and I am almost sure that Bing's too) algorithm is well aware of that the homepage is often called home.php, home.html or home. They are not stupid. I have read it several years ago in some interview with somebody from Google. This will do nothing with your "score" in search results. What is the best practice to name the default controller and default model? - El Forum - 06-14-2012 [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". What is the best practice to name the default controller and default model? - El Forum - 06-14-2012 [eluser]nagata[/eluser] In that case feel free to read through this tutorial on how to make one such http://ellislab.com/codeigniter/user-guide/tutorial/static_pages.html What is the best practice to name the default controller and default model? - El Forum - 06-14-2012 [eluser]Samus[/eluser] [quote author="TWP Marketing" date="1339699442"]Just a suggestion on naming; the use of "home" as a controller name is not a good idea for SEO purposes, unless you website just happens to be about "homes". Pick a name that relates to your site so the search engines will recognize that it relates to your content. Also pick a name, other than "home", for the first item in your main menu, again because the engines will downgrade your rank if it doesn't relate to page content. [/quote] irrelevant if you're routing. ![]() |