K
K
kolya_krut2017-07-26 14:34:38
Yii
kolya_krut, 2017-07-26 14:34:38

How to set Yii2 component messages?

Hello.
Some component for Yii2, which is installed via Composer.
How to correctly configure the component code so that the component has its own messages (on errors and just messages), and at the same time, after installing it through composer in the application, the messages can be overridden?
What settings should be in the application for such a case?
Example. Let's say the component's messages are located in the vendor/package/src/messages directory. Somewhere in the component's code, a message is called:

throw new \ErrorException(\Yii:t('component', 'absolutely_peace_death'));

If there is a message file in the application (@app/messages or somewhere else), then read the message from there. Otherwise, read from the component file (vendor/package/src/messages).

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
Boris Yakushev, 2017-07-26
@za4me

If the file exists

Throw a standard php function that checks the file for existence? :)

D
Dmitry Bay, 2017-07-27
@kawabanga

So, you create a child class in app/components. and call it. work your magic in it.

K
kolya_krut, 2017-07-27
@kolya_krut

magic is bad) it is not clear how it works) it is necessary that it be as transparent as possible
for yourself to find such a solution (you never know, maybe it will come in handy for someone), which does not seem to violate the behavior of the framework:
works through normal Y::t() behavior without any extra standard functions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question