Ejemplo n.º 1
0
 public function findModel($id)
 {
     if (($model = Country::findOne($id)) !== null) {
         return $model;
     } else {
         throw new \yii\web\NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
     }
 }
Ejemplo n.º 2
0
 public function run($id)
 {
     $id = (int) $id;
     $output = [];
     if (($model = \common\models\country\Country::findOne($id)) !== null) {
         if ($model->delete()) {
             $output = ['error' => false, 'message' => Yii::t('app', 'Successfully deleted!')];
         }
     }
     if (empty($output)) {
         $output = ['error' => true, 'message' => Yii::t('app', 'The requested page does not exist.')];
     }
     return \yii\helpers\Json::encode($output);
 }
Ejemplo n.º 3
0
 public function run($search = null, $id = null)
 {
     $out = ['more' => false];
     if (!is_null($search)) {
         $query = new Query();
         $query->select('[[id]], [[name]] AS [[text]]')->from('{{%country}}')->filterWhere(['like', '[[name]]', $search])->limit(20);
         $command = $query->createCommand();
         $data = $command->queryAll();
         $out['results'] = array_values($data);
     } elseif ($id > 0) {
         $out['results'] = ['id' => $id, 'text' => Country::findOne($id)->name];
     } else {
         $out['results'] = ['id' => 0, 'text' => Yii::t('app', 'No matching records found')];
     }
     return Json::encode($out);
 }
Ejemplo n.º 4
0
 /**
  * Finds the Country model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Country the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Country::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }