Answer the question
In order to leave comments, you need to log in
Why getImage() - Yii2 swears?
Valar Morghulis!
<?php
namespace app\controllers;
use app\models\About;
use Yii;
class AboutController extends AppController
{
public function actionView()
{
$about = About::find()->where(['status' => '1'])->limit(6)->all();
$this->setMeta('E-SHOPPER О Компании');
return $this->render('view', compact('about'));
}
}
<?php
namespace app\models;
use yii\db\ActiveRecord;
class About extends ActiveRecord{
public function behaviors()
{
return [
'image' => [
'class' => 'rico\yii2images\behaviors\ImageBehave',
]
];
}
public static function tableName(){
return 'about';
}
}
<?php foreach($about as $about2): ?>
<?php $mainImg = $about->getImage();?>
<?= Html::img($mainImg->getUrl('268x249'), ['alt' => $about->name])?>
<p><?= $about2->content?></p>
<?php endforeach;?>
$content
loads, and if I insert an image, then the next. mistake:Call to a member function getImage() on array
Answer the question
In order to leave comments, you need to log in
$about->getImage()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question