Beispiel #1
0
 /**
  * Get Spec.
  * @return Spec
  */
 public function getSpec()
 {
     return $this->hasOne(Spec::className(), ['id' => 'id_spec']);
 }
 /**
  * Spec list.
  *
  * @return mixed
  * @throws BadRequestHttpException
  */
 public function actionSpecList($q = null, $id = null)
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $out = ['results' => ['id' => '', 'text' => '']];
     if (!is_null($q)) {
         $query = new Query();
         $query->select('id, CONCAT_WS(" ", `code`, `name`) AS text')->from('spec')->where(['like', 'name', $q])->OrWhere(['like', 'code', $q])->limit(20);
         $command = $query->createCommand();
         $data = $command->queryAll();
         $out['results'] = array_values($data);
     } elseif ($id > 0) {
         $out['results'] = ['id' => $id, 'text' => Spec::find($id)->name];
     }
     return $out;
 }
Beispiel #3
0
 /**
  * Finds the Spec model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Spec the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Spec::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }