Module Structure In Yii Application


My site got three section 1> Buyer 2> Seller 3> Admin. To implement these section using yii what would be the best structure to develop this site? As i am new in yii, should i go with module? Does this module architecture follow HMVC? Can you please guide me.



It sounds like the Yii 2 advanced application template might be a suitable starting point. Note that Yii 2 is in beta though.

Thanks Keith for your quick reply. With version of yii 1.4, wouldnot it be possible?

Admin is usually a module. As for the Buyer/Seller? They could just be separate controllers. There would be considerations if buyer/seller use the same models, and how different the model interactions are.

If they can use the same models, then separate controllers is good enough. If MAJOR differences in the model uses then separate models might be called for.

p.s. What’s the H in the above HMVC mean?

Thanks jkofsky,

           HMVC stands for 'Hierarchical Model View Controller', that CodeIgniter applications does follow very well. In my application i have 3 sections means seller, buyer, admin and each of them has their own sub-ordinate modules like seller has product, login. Buyer has account, login. Admin has login, RBAC, product, category etc. So, i think we have to go for nested module structure. But i am not sure as i have no work experience in yii framework.

I can see how you could do this 3 controllers (site,seller,buyer) and an admin module (maybe RBAC Module). Since you mentioned that admin would have RBAC, all logins could/would use that. You could have a column in the user table that indicates user is seller/buyer, or if user could be both than some way of setting what they are at this moment.

In my project i have different tables for seller and buyer. I have started to follow the nested modules structure, but facing a problem with CRUD generator. My intention is to have a single model folder for all models. I can manage to create controllers to specific nested module folder but unable to handle the views. View creation has been done to the first level or in root level. As off now i just cut the view folder and paste it to the specific module folder. I don’t know you get me or not.

To me is seems a little complicated, but if it works for you…Go for it.

CRUD generation: in the gii generator, there is a input field that you can put where to place the code. I know that admin/controller generates the code in the admin module. Maybe it works with admin/buyer/controller would if buyer was a sub module of the admin module. Other wise cut & paste works.

Thanks jkofsky for your interest, it’s a real help. Can you please tell me whether yii supports HMVC structure or not? With this moduler approach, view is generating in top level which i have to cut n paste to proper module. I am confusing about my approach because templating at sub-module level does not follow code reusibility. We need to write the same code in every sub-modules.

As I have never heard of 'H’MVC before, I’m guessing that Yii doesn’t actually ‘support’ it natively.

As for your project, I would look at simplifying this, or look into sub-classing things. If 10% of your sub-module is different, then put the 90% in a base class and extend it to write the other 10%.

View generation: I think you should be able to generate in the sub-module by telling Gii where to put it. As stated earlier, when you generate the CRUD stuff, one of the ControllerID entery says if you put admin/model it with generate the files in the admin module, if it exists. Try putting in moduleID/subModuleID/model, and see where the file are going when you generate the preview.

Then what does HMVC offer that modules doesn’t have? Because i have a bit working experience on Code-igniter and i found the moduler approach is there which they called HMVC(Hierarchical Model View Controller).

It could be that modules in Yii IS the H in Code-igniter…I don’t know :(

I was just saying that if controller code is 90% the same extend your controllers from a common controller with the 90%. Then the individual controllers can get the other 10%.

If it’s the views then then use of renderPartial() the various pieces could work. I have a project that the user can view/update your profile information. This info comes from 2 tables. So I have one view.php file that has 2 renderPartials() that show the 2 parts of the information. When view.php is called I pass both models in. You could do something similar. One view file with renderPartial the 90% in common, another renderPartial for the remaining 10%.