/** * Lists all Cars models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Cars::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
public function actionGetCars($cat) { // $cat = $_POST['cat']; $autos = Cars::find()->where(['category' => $cat])->all(); // var_dump($autos); $count = 0; $code_prev = 1; $code_next = 1; $resp = Html::tag('div', Html::tag('span', '', ['class' => ['glyphicon', 'glyphicon-remove'], 'aria-hidden' => 'true']), ['id' => 'close']); foreach ($autos as $auto) { $resp .= Html::tag('div', Html::img(Url::to('@web/src/upload/') . $auto->photos[0]->url, ['class' => 'img-responsive', 'style' => 'width:90%; margin: 0 auto']) . '<p>' . $auto->name . '</p></div>', ['class' => 'col-sm-6', 'id' => 'prefix-' . $auto->id]); } // var_dump($resp); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['result' => $resp, 'code_prev' => $code_prev, 'code_next' => $code_next]; }