P
P
prodvair2019-02-26 13:35:54
Yii
prodvair, 2019-02-26 13:35:54

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');
}
}
?>

call in controller
Lots::find()->orderBy('id')->limit(12)->all();

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Volintsev, 2019-02-26
@prodvair

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.

D
Dmitry Bay, 2019-02-26
@kawabanga

table exactly with a buck in the middle and brackets?

M
morricone85, 2019-02-26
@morricone85

return 'obj$lotsGet()';

What is the difficulty in renaming a table?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question