confused using modules


i’m starting to write a project based on yii and want to write this new project in some modules…

i used the yiiuser and yiiusermanagment modules before but for this project i can not use them and i must write them myself

i want write my user system as follow :

user module

profile module

membership module

rbac module

these modules are related together very closely and i’m confusing write and using modules!!

is these my Decision for this design true???

how can i communicate between these modules and main application???

is modules working fully independet eg. gii?

i confused using modules!!!

please help and explain more about modules for me !!

There is no bad not correct way about Modules, although if you do plan to have other developers working on parts of the site then it is a good practice to break down the code in smaller containers.

Thus if in your project there will be more developers active (e.g 1 developer working on profiles, other working on memberships etc) or you are planning on releasing the code under open source license, then yes it would be practical to break down the code into modules.

Modules are like bricks (in big applications), small parts interconnecting together but with different tasks.

this project is big and i decided to write it on modules but i need more info(even samples) about modules in yii

i reviewed zurmo sorce code and tracksar sample project and other samples but…

As petkostas already said: There is no right or wrong in this case. Usually people use modules when they write parts of an application that are largely independent of the rest of the app. The user management modules are a good example as they offer pure backend functionality that isn’t needed by the frontend. Or imagine admin modules which are very specialized on the tasks of the admin and no one else. Or site statistic modules specialized on creating/querying tables full of information about visitors etc.

The idea is that when you add/remove a module the app should still work as expected just with/without the modules functionalities.

When two (or more) modules have a strong dependency on each other and/or share many resources (e.g. models), it’s probably better to merge them into one module.

To decide if you need modules at all, ask yourself some questions:

Do you want to be able to

  • reuse your modules between applications?

  • deploy modules independently from each other?

  • enable/disable modules easily from application configuration?

If the answer is NO for all the above questions then there’s probably no need for modules.

For better code organization and auto-magic URL management you can simply create subdirectories in protected/controllers (with the correspondig subdirectories in protected/views) and Yii will find and handle them properly.

in this case if these modules removed from configuration then some features for example registration, login and … no longer exists and so app don’t work as i expect !! but i want to reuse them in other projects …

merging them is good idea that also me thought about it …

my answer to questions :

1- reuse : yes i need reuse this user system in other project…any idea??

2- i prefer this independenty of modules but in this case it’s confusing for example if design the user(register, login,…) and profile modules in two separate module then when i implement the register action in loginController of user module i must access to profile model for example birthday, first name, phone number and etc…

3-enable/disable modules easily is very good method but i dont sure about my own case.