A
A
akula222016-03-17 11:11:22
Yii
akula22, 2016-03-17 11:11:22

Where to insert a function (method)?

I display a list of news, in the controller the request is $dataProvider = new ActiveDataProvider([ .....
in the index.php view

<?= ListView::widget(
            [
                'dataProvider' => $dataProvider,
                'layout' => "{items}\n{pager}",
                'itemView' => '_index_item',

further in _index_item.php I display
the news themselves
$model->title
$model->short
I need to trim the short text correctly, I have a trimText function that does this.
Question: Where would it be logical to place this function (method) in the model, but how can I use it in the view, tell me the right solution, or is it all done in the controller?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2016-03-17
@akula22

In the model getShortText() implement whatever you want and use $model->shortText

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question