Answer the question
In order to leave comments, you need to log in
How to correctly implement static data output in yii2?
Hello ;)
While continuing to learn yii2, I came across such a problem.
In the simplest case: there is a "Contacts" page, it has a block with a feedback form (on the right), at the bottom there is a map, and to the left of the feedback form there is a block with text (phone number, email, etc.).
This text should be edited in the admin panel, respectively, it is necessary to make a `page` table (exaggerated):
id | page_content
And the question arises, how to display such data? Correctly I think - to make a widget for them, and in the place where the data should be displayed, initialize it? Because There are other pages, for example the main one.
And what to do if, for example, on the page of the same name there should be 2-3 blocks with such data?
Answer the question
In order to leave comments, you need to log in
Good afternoon.
You can write this data in the params.php file.
Output like this:
You can make a settings module.
You can do as you say, the page table and display the information you need on the "contacts" page.
There are many options.
Here it is worth breaking the problem into several.
1. How to store - in the database
2. How to receive and edit - I would make a component for such things, conditionally "site settings", under it 1 or several pages, would receive data and cache for an indefinite period, would clear the cache when acting in CRUD in the admin. It is convenient to receive something like this:
3. How to display - here either your widget or block ( www.yiiframework.com/doc-2.0/yii-widgets-block.html ) or just a separate view.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question