I have a Array from MySql Query and What I did is convert it to object. But after convert into object Is has become object of stdClass() So I want it to be a object of Theme class.
My Cotroller Code
public function actionIndex()
{
// $theme = Theme::find()->all();
$query = "SELECT t.*,COUNT(d.id) AS total_downloads FROM `themes` AS T
LEFT JOIN downloads AS D
ON D.theme_id = T.id GROUP
by t.id ORDER BY total_downloads DESC LIMIT 6";
$connection=Yii::$app->db;
$trends = $connection->createCommand($query);
$model = $trends->queryAll();
return $this->render('index',[
'model'=>$model,
]);
}
And View Code Look Like
<?php foreach ($model as $themes): ?>
<?php $theme = (object) $themes; ?>
<?php var_dump($theme) ?>
<div class="col-md-4">
</div>
<?= $theme->name ?>
How can I covert $model
to a object of class Theme.php