Hi all,
The pagination below is working properly for the field names in the table Products; however, when pulling variable data from tables Power or Categories I receive the notice “Array to string conversion”. I’m not sure if the problem exist in the controller or the view. When $products is printed, variable data appears for both Power and Categories. Thanks in advance for pointing me in the right direction.
Controller
public function actionIndex()
{
$query = Products::find()
->where(['brand_id' => 101])
->joinWith(['power', 'categories']);
$pagination = new Pagination([
'defaultPageSize' =>4,
'totalCount' => $query->count(),
]);
$products = $query
->orderBy('product_name')
->offset($pagination->offset)
->limit($pagination->limit)
->all();
return $this->render('index', [
'products' => $products,
'pagination' => $pagination,
]);
}
View
<div class="col-xs-6 col-sm-3"><?= $products['product_name'] ?></div>
<div class="clearfix visible-xs-block"></div>
<div class="col-xs-6 col-sm-3"><?= $products['power'] ?></div>
<div class="col-xs-6 col-sm-3"><?= $products['category_name'] ?></div>
When I print the data for $products the following power.power_id & power.power show values. Likewise values appear for Categories.
[_related:yii\db\BaseActiveRecord:private] => Array
(
[power] => Array
(
[0] => common\models\Power Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[power_id] => 3
[power] => Electric and Gas