Ejemplo n.º 1
0
 /**
  * js(on)country 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 actionJscountry($search = NULL, $id = NULL)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $clean['more'] = false;
     $query = new Query();
     if (!is_Null($search)) {
         $mainQuery = $query->select('id, iso3 AS text')->from('{{%net_frenzel_country}}')->where('UPPER(iso3) LIKE "%' . strtoupper($search) . '%"');
         $command = $mainQuery->createCommand();
         $rows = $command->queryAll();
         $clean['results'] = array_values($rows);
     } else {
         if (!is_null($id)) {
             $clean['results'] = ['id' => $id, 'text' => Country::findOne($id)->iso3];
         } else {
             $clean['results'] = ['id' => 0, 'text' => 'None found'];
         }
     }
     return $clean;
 }
Ejemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function validateCountry()
 {
     if ($this->country_id !== null) {
         $country = Country::findOne($this->country_id);
         if ($country === null) {
             $this->addError('country_id', Yii::t('location', 'Country with id {[id]} doesn\'t exist', ['id' => $this->country_id]));
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 3
0
 public function actionDemo($id)
 {
     return Country::findOne($id);
 }