Answer the question
In order to leave comments, you need to log in
Getting data from the database in Yii2. How to do it?
Hello. Could you help me with one problem?
I want to get data from db to create API. But I have a problem when I make a request to say that there is no such table. Although in fact it has already been created and it already has data. The only thing is that the name of the table is crooked and made in the form of an object.
Model
<?php
namespace frontend\models;
use Yii;
use yii\db\ActiveRecord;
class Lots extends ActiveRecord
{
public static function tableName()
{
return 'obj$lotsGet()';
}
public static function getDb()
{
return Yii::$app->getDb('obj');
}
}
?>
Lots::find()->orderBy('id')->limit(12)->all();
Answer the question
In order to leave comments, you need to log in
Apparently, this is not a table, but a computable function that returns a dataset.
Do not use ActiveRecord to work with these records, form SQL queries manually.
return 'obj$lotsGet()';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question