At this moment i am having a problem, my controller called userspace, his model called userspace and view is userspace too, logically everything is fine, but just a plain example when you open this 3 files sometimes it's hard to understand where is model and where is controller if not to start reading the code. So i ask for advises or examples of coding standarts :)
3条回答 默认 最新
dongtangyi8962 2013-11-09 13:14关注I normally tend to use singular/plural to distinguish from model/controller. That being said, this is how I do things:
Model
- File name: app/classes/model/userspace.php
- Class name: Model_Userspace
This is also FuelPHP's naming convention (at least for Models). This way you don't have to specify the table name on the model, like so:
protected static $_table_name = 'userspaces';because FuelPHP will look for the plural version of your model name.
Controller
- File name: app/classes/controller/userspaces.php
- Class name: Controller_Userspaces
Views
- Folder: app/views/userspaces/
This keeps things organized per controller name. For each controller action, a view should be created. So, if you have a create and edit action in your Controller_Userspaces, you will create the following files:
- Create: app/views/userspaces/create.php
- Edit: app/views/userspaces/edit.php
Forging the views should be a matter of calling:
View::forge('userspaces/create'); View::forge('userspaces/edit');You should check the FuelPHP ORM documentation for more information.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报