P
P
progreg2013-12-12 11:56:25
Yii
progreg, 2013-12-12 11:56:25

How good or bad is strong coupling in Yii, and is it possible to make something similar to Service Locator for Yii?

%D0%A5%D0%B8%D1%82%D1%80%D0%B5%D1%86-%D0
Hello, I have a Yii question. How good or bad is strong coupling in Yii, and is it possible to make something similar to Service Locator for Yii?. Before that, I worked with Magento and really liked the ability to redefine entities for all modules of the system. Now I'm trying to implement a modular structure for Yii, put configurations into modules for ease of writing, now it's up to Service Locator. Are there ready-made solutions or concepts of solutions, and do I need it at all?) Maybe I'm looking in the wrong direction? According to my logic, the Service Locator is needed because one change for all binders is very useful.
I must say right away that I am not yet strong in Yii, so please do not kick much. Any criticism is well received. Thanks

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vit, 2013-12-12
@fornit1917

Not a component, but for example a model for the User module, while all modules that use this model receive a new class.

A model is a special case of a component. For them, you can also use the DI mechanism.
For example, instead of
you can write everywhere
where $configManager is some fairly simple object of yours that will load information on the word "user" from a single config and return it as an array. In this array, you can set the class field - the actual instance of this class will be created by the Yii::createComponent function.

R
Roman Domrachev, 2013-12-12
@MrLoki

SL or DiC is not suitable for Yii, the creators of the framework talked about this, including on Habré . For external logic, you can wind up something of your own.
If you're looking at DiC or SL, try Symfony2, Zend 2, Laravel 4, or something else. Yii has its own way, get used to global access.
Answering the question of the breakdown of components.
We configure in the components section and get access through Yii::app(). Everywhere.
Modules are. But they work strangely, and we did not understand each other. Try you.

A
Alexander Makarov, 2014-04-17
@SamDark

Beta 2.0 included the DI container and the locator service.

M
Mikhail Osher, 2013-12-12
@miraage

So you want to redefine the component? What is the problem? Specify the required class in the config, in the components section.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question