M
M
Mark2020-01-11 11:37:23
Yii
Mark, 2020-01-11 11:37:23

How to get text messages from a file so as not to clutter up the Yii2 code with them?

The service has a notification system for the user, notifications are stored in the database.
But their text is written in the code, which greatly clutters it up. For example:

Sample text

$this->noticeService->add(
            $event->ticket->user_id,
            "Ответ в тикете: " . $event->ticket->subject,
            "Вам поступил ответ от поддержке в тикете: " . Html::a($event->ticket->subject, $link),
            'life-ring',
            'info'
        );


Is it possible to transfer at least messages to files using Yii2, as in Mailer, and how to do it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim, 2020-01-14
@MarkLb

Of course you can! What's the problem?) Do the same as in Mailer. You can at least send HTML there as in mailer. The mailer has a text template and an HTML template.
Create a php file. Insert the necessary variables into it and get the data from this file, replacing the variables.
If this option does not suit you, then you can use translations. There are no other options. And why not)

A
Access Denied, 2020-01-11
@AccessDenied80

Framework tools can be stored and used in translation files Yii::t()
https://yiiframework.com.ua/ru/doc/guide/2/tutoria...

L
lubezniy, 2020-01-11
@lubezniy

In view it is normal to do them. If you need to change without coding, then drive it into the database and make the admin panel.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question