public function actionIndex() { $lst = Sanpham::find()->where(['status' => 1])->all(); $result = []; if (count($lst) > 0) { foreach ($lst as $item) { $line = Loaisanpham::findOne($item->id_lsp); array_push($result, ['station' => $item, 'line' => $line]); } } return $this->render('index', ['listLine' => $result]); }
/** * Finds the Loaisanpham model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Loaisanpham the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Loaisanpham::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionPreview($id) { $model = Loaisanpham::findOne($id); return $this->render('preview', ['model' => $model]); }