S
S
Snewer2017-03-18 18:15:17
Yii
Snewer, 2017-03-18 18:15:17

How to pass static data from model to view?

Hello!
Models have static methods for generating a list of data that is passed to the dropdown form field in the view. Is it ok to call this static method directly on the view?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Shaks, 2017-03-18
@shaks

Yes

M
Maxim Fedorov, 2017-03-19
@qonand

Depending on what is considered a model, if your model is \yii\base\Model - then the function for getting a static list should be placed in it.
If your model is ActiveRecord then it all depends on the data you are going to return. For example: if this is a list of some constants related to the current ActiveRecord, then it is acceptable to place it in the ActiveRecord itself (although this is not ice). If your list of data is taken from another model, then it is worth introducing a separate view model and placing the algorithm for obtaining data in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question