Пример #1
0
 /**
  * js(on)entity returns an json object for the select2 widget
  * @param  string $search Text for the lookup
  * @param  integer of the set value
  * @return json    [description]
  */
 public function actionJsentity($search = NULL, $id = NULL)
 {
     header('Content-type: application/json');
     $clean['more'] = false;
     $query = new Query();
     if (!is_Null($search)) {
         $mainQuery = $query->select('id, name AS text')->from('{{%entity}}')->where('UPPER(name) LIKE "%' . strtoupper($search) . '%"');
         $command = $mainQuery->createCommand();
         $rows = $command->queryAll();
         $clean['results'] = array_values($rows);
     } else {
         if (!is_null($id)) {
             $clean['results'] = ['id' => $id, 'text' => Entity::findOne($id)->name];
         } else {
             $clean['results'] = ['id' => 0, 'text' => 'None found'];
         }
     }
     echo Json::encode($clean);
     exit;
 }
Пример #2
0
 /**
  * Finds the Entity model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Entity the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Entity::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }