简体   繁体   中英

Yii Framework a Model / Controller for every different table?

I'm new to Yii framework and trying to work on a simple product page. In this Product section, there is product listing (calling Product table), Groups (Calling Group table), Modifier (Calling Modifier table).

Should I have the Files structure as below :-

Models Folder
   - products.php 
   - groups.php
   - modifier.php

Controller Folder
   - ProductsController.php
   - GroupsController.php
   - Modifier.php

Views Folder 
   - Products Folder
       - products.php
       - uploadproduct.php
       - addEditProduct.php
   - Groups Folder
       - groups.php
       - addEditGroup.php
  - Modifier Folder
       - modifier.php
       - addEditModifier.php

OR should I combine all into one "Product Folder" and all under ProductController, since the Groups and Modifier will just have the add/edit function ?

What is the best way to do this, and if you could explain to me why that is much appreciated. Thank you so much !

Yii Framework uses the MVC (Model-View-Controller) approach. http://www.yiiframework.com/doc/guide/1.1/en/basics.best-practices

It is smart to separate each part of MVC accordinly, it keeps organized and simple to perform a maintenance

So, since you have 3 structures in your project (Product, Groups and Modifier), it is better to avoid mixing them.

They could access the same table as you desire, however, each part of your project will perform a different action/task.

If you want, you can use a nice tool in Yii Framework called gii, to generate code for you project, like CRUD, Controllers, Models. http://www.yiiframework.com/doc/guide/1.1/en/topics.gii#extending-gii

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM