A
A
Alexey Sopin2016-02-18 14:22:55
Yii
Alexey Sopin, 2016-02-18 14:22:55

How to convert CActiveRecord model to ActiveRecord on the fly?

There is a project on Yii1, I want to use a widget written in Yii2 (I use the bridge https://github.com/neam/yii-yii2-bridge). The model in the view is a descendant of CActiveRecord. The widget checks whether the model is an instance of the ActiveRecord class, and then uses some of the features of Yii2 ActiveRecord.
Is it possible to convert the model on the fly to the ActiveRecord type in the view without creating a separate class for my table that inherits Yii2 ActiveRecord?
Now I did this, I get the error The table does not exist: {{%active_record}} in the widget:

CheckboxMultiple::widget([
                    'model' => new \yii\db\ActiveRecord($model->findAll()),
                    'attribute' => 'someIds',
                    'attributeLabel' => $model->getAttributeLabel('someIds'),
                    'data' => someHelper::all()
                ]); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2016-02-20
@matios

In Yii1, table names in models are set like this: {{my_table}}
In Yii2, table names in models are set like this: {{%my_table}} See the
difference?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question