I'm writing my first Codeigniter site using the MVC pattern. I'm building some controllers that load views now (haven't gotten to Models yet) but I'm noticing that my View and Controller files have the same filename (like products.php). They are in their respective folders of course. For example I have an About controller, that loads an About view, both of which are named about.php. I have a Products controller that loads a Products view which are both named products.php. Is this good practice?
From reading and studying it seems everyone names their models differently,开发者_C百科 like Products_Model.php, which makes it easy to distinguish, but I can't recall seeing anyone doing anything different with the controllers and views.
Am I setting myself up for a headache down the road when this site develops more? Thank you!
What I do when writing CodeIgniter sites is creating a folder same as the controller name in my views
And if I have a method called index(), it'll view: /views/controller_name/index.php.
In your controller you can do this: $this->load->view('controller_name/index'); so you can load the file inside the folder.
The only annoying thing I find is the tabs in your IDE are both marked 'products.php' and it's hard to tell them apart. I tend to tack '_view'
onto the end of the view files now. Just do what feels right. It's not that hard to change filenames later on.
The controller and model usually have the same name. This makes it easy for your main controller to call on the correct controller and model depending on a certain page name.
And in most cases it's logical to use similar names, e.g. with multiple views.
application/ controller/ customers.controller.php products.controller.php model/ customers.model.php products.model.php view/ customers_list.php customers_add.php products_list.php products_export.php
精彩评论