Using modules. How? For what?

I don’t understand for what and how to use modules.

  1. For example, is it easy to connect module to existed application with existed layouts, design e.t.c? Module has his own layouts, design, etc and can’t use application layouts. As a result, we have our application with module with its own design. Is it layouts copy/past from application to module?

  2. I understand, that cross-action calls from application to module logic and from another modules will increase coupling(strong coupling) between application and modules. But I can write module for managing of this relationships between application, modules e.t.c. (for example, ports system in FreeBSD, package manager in Debian e.t.c).

How can I decompose the system on its component parts with saving of ability to exchange messages between parts of the application?

Coclusion. How can I use modules? For what? It seems useless without the possibility to exchange messages between the modules and applications.

Modules are generally useful when your application is so complex, that it would be a maintainability nightmare to keep track of all methods in the default module.

Most applications don’t need this feature I think, as adding one or two controllers in a separate module comes with a senseless price.

You might introduce a back-end module for administrators if that deserves its own place in your application (with unique layouts, etc.).

Hi,

I am also new to Yii. SO my reply may not be up to the mark.

I am using modules in my applicatinos simply to create independent application components.

e.g. I have a module named "masterdata" and has many different sectinos. So my application runs using the followin style of urls:

index.php?r=masterdata/customers/add

index.php?r=masterdata/customers/edit/91

index.php?r=masterdata/products/add

index.php?r=masterdata/products/edit/12

index.php?r=masterdata/countries/add

index.php?r=masterdata/languages/add

index.php?r=masterdata/bankacconts/add

index.php?r=masterdata/bankacconts/edit/3

Other module is named "contracts" and i have my application work like this:

index.php?r=contracts/salescontract/add

index.php?r=contracts/salescontract/edit/91

index.php?r=contracts/purchasecontract/add

index.php?r=contracts/purchase/edit/12

and so on…

So these modules are independent and can be separated for ease of management etc.

Hope it satisfies…

Only if we are talking about small web applications. These applications do not need to update and maintain multiple servers.

And if the application user wants to update its own application, install new modules?

Let’s imagine that yii is our mini OS.

It is much easier to operate, maintain yii application if we had such opportunities as the package manager in * nix.

What you do in your operating system (control package) you can make in web applications

They are like self-container applications, but they are integrated into the main webapp by their urls.

A module can use its parent’s models and components (and presumably anything else declared in main.php ‘import’). Thus you can, for example, have a common BaseController do say User::model()->tableName();

You can use a theme for the site. A theme is available to all modules. (Views are linked to their Components).

Never copy and paste code. It creates a maintenance nightmare.

Why on earth would you consider building something to solve a problem that you can avoid? If you need to share something then use one of the many mechanisms available to you. Even if you hack something in one of these, it’s better than building something entirely unnecessarily.

You don’t need to “decompose” it! Why would you ever want to? Perhaps MVC isn’t the right tool for the job you need to do.

They’re not useless; they do what they are designed to do.

Just to add that if you want to access your modules’ components and/or models, add something like the following to the webapp’s main.php:




	'import'=>array(

		'application.models.*',

		'application.components.*',

		'application.modules.<module_name>.components.*',

		'application.modules.<module_name>.models.*',

	),