B
B
bizzonaru2017-02-01 12:44:57
Yii
bizzonaru, 2017-02-01 12:44:57

How to make ActiveRecord mongodb return a prayer, but an array?

I am using Yii mongodb extension, getting data and drawing in grid. By analogy, as MySQL wanted to customize the value of a column, it turns out that by default, not a model is passed to an anonymous function, but just an array.

[
                                    'attribute' => 'type_id',
                                    'label' => 'Список',
                                    'value' => function($model) { 
                                        return print_r($model, true);  // здесь нельзя работать как с моделью вызывая из неё функции
                                    }                                    
                                ],

use yii\data\ActiveDataProvider;
use yii\mongodb\Query;


            $query = new Query();
            $query->from('tariffs')->where(['user_id' => $user->id]);     

            $dataProvider = new ActiveDataProvider([
                'query' => $query,
                    'pagination' => [
                    'pageSize' => 10,
                ]
            ]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-02-01
@bizzonaru

It turns out that by default, not a model is passed to an anonymous function, but just an array.

The data that you generated is transferred to the anonymous, in this case you generate the data using yii\mongodb\Query. Query is a normal query not bound in any way to objects. If you want to bind the result of a query to an object, use yii\mongodb\ActiveQuery

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question