S
S
sdgs4s4 .2017-09-20 16:31:18
Yii
sdgs4s4 ., 2017-09-20 16:31:18

Yii2 output information from the database?

Valar Morghulis!
I can't retrieve information from the database, help me out

Controller

class AboutController extends AppController
{
    public function actionView()
    {
        $about = About::find()->where('id' >= 1)->limit(6)->all();
        return $this->render('view', compact('about'));
    }
}


Model

class About extends ActiveRecord{

    public function behaviors()
    {
        return [
            'image' => [
                'class' => 'rico\yii2images\behaviors\ImageBehave',
            ]
        ];
    }

    public static function tableName(){
        return 'about';
    }

    public function About(){
        return $this->hasMany(About::className(), 'id' >= '1');
    }

}


View

<?= $about->name?>

I extract information about the company from the database (I didn’t know how to do it, so I did it by ID)
DB (zhmyak)

912f47b277b840a39eb7c48227696714.PNG

Please edit the code so that I can display information (all 3 id). Doesn't output anything at the moment.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Novikov, 2017-09-20
@Encoderast

In the controller

return $this->render('view', [
    'about' => About::find()->where(['>=', 'id', 1])->limit(6)->all(); // <= where другой
]);

The About function should be removed altogether from the model, as it can be called as a constructor in older versions of PHP. In addition, it still won't work, since it is calculated as true, and is not used for fitration in the request . In the form, $about will contain an array, since it is the array that is searched in the controller via ->all(); doka

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question