Beispiel #1
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.');
     }
 }
Beispiel #2
0
 /**
  * Загружает запись модели текущего контроллера по айдишнику
  * @param $id
  * @return null|static
  * @throws \yii\web\HttpException
  */
 public function loadModel($id)
 {
     $model = Country::findOne($id);
     if ($model === null) {
         throw new \yii\web\HttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionCountry()
 {
     $countries = Country::find()->orderBy('name desc')->all();
     echo \yii\helpers\Json::encode($countries);
     $countryUs = Country::findOne('US');
     echo '<br />' . \yii\helpers\Json::encode($countryUs);
     $countryUs->name = 'U.S.A.';
     echo $countryUs->save() ? '  OK' : '  False';
 }
 public function actionIndex()
 {
     $query = Country::find();
     $pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $query->count()]);
     $countries = $query->orderBy('name')->offset($pagination->offset)->limit($pagination->limit)->all();
     $country = Country::findOne('US');
     $country->name = 'U.S.A.';
     $country->save();
     return $this->render('welcome', ['countries' => $countries, 'pagination' => $pagination]);
 }
Beispiel #5
0
 function actionTest()
 {
     $db2 = \Yii::$app->db2;
     $rows = (new Query())->select('*')->from('country')->limit(10)->all($db2);
     $count = (new Query())->from('country')->count('*', $db2);
     //查询当前country表总数
     //select查询部分使用数组
     //$query = (new Query())->select(['country_id','country'])->from('country');
     //$command = $query->createCommand($db2);
     //echo $command->sql;//查看当前的SQL文件
     //列合并
     //$query = (new Query())->select(['CONCAT(country_id, country) AS country_full'])->from('country');
     //$command = $query->createCommand($db2);
     //echo $command->sql;
     //where andWhere filterWhere andFilterWhere orFilterWhere
     //$query = new Query();
     //$country_value = 'China';
     //$query->where(['country_id'=>23]);//此处不支持绑定
     //$query->andWhere(['like','country','']);
     //添加andWhere条件 不会移除条件中的空值
     //if ($country_value) {
     //$query->andWhere(['like', 'country', $country_value]);
     //}
     // filterWhere() 最大的区别是从提供的条件中移除空值
     //$query->filterWhere(['country'=>$country_value]);
     //$query->filterWhere(['like', 'country', $country_value]);
     //$query->orFilterWhere(['country'=>'Colombia']);
     //var_dump($query);exit;
     //$query->from('country');
     //$command = $query->createCommand($db2);
     //$result = $command->queryAll();
     //echo $command->sql;exit;
     //var_dump($result);exit;
     //批量查询
     //$query = (new Query())
     //    ->from('country')
     //    ->orderBy('country_id');
     //foreach ($query->batch(100,$db2) as $countries) {
     //    var_dump($countries);//第一次先取出100条数据,第二次在取出100条,不足100条的,直接显示
     //}
     //返回 yii\db\ActiveQuery 实例,并向AR实例里填充数据
     //$countries = Country::find()->indexBy('country_id')->all();
     //var_dump($countries);
     //返回 AR 总数
     //$count = Country::find()->count();
     //var_dump($count);
     //        $country = new Country();
     //        $country->load();
     //
     $country = Country::findOne(1);
     $address = $country->address;
     var_dump($address);
     return $this->render('test');
 }
Beispiel #6
0
     }
 } else {
     if ($s == 'emp_padd') {
         if ($sd['emp_master_emp_address_id'] != 0) {
             if (!empty(EmpAddress::findOne($sd['emp_master_emp_address_id'])->emp_padd_city)) {
                 $add_c = "<br/>" . City::findOne(EmpAddress::findOne($sd['emp_master_emp_address_id'])->emp_padd_city)->city_name . ", ";
             } else {
                 $add_c = '';
             }
             if (!empty(EmpAddress::findOne($sd['emp_master_emp_address_id'])->emp_padd_state)) {
                 $add_s = State::findOne(EmpAddress::findOne($sd['emp_master_emp_address_id'])->emp_padd_state)->state_name . ", ";
             } else {
                 $add_s = '';
             }
             if (!empty(EmpAddress::findOne($sd['emp_master_emp_address_id'])->emp_padd_country)) {
                 $add_co = Country::findOne(EmpAddress::findOne($sd['emp_master_emp_address_id'])->emp_padd_country)->country_name;
             } else {
                 $add_co = '';
             }
             echo "<td class='text-center'>" . EmpAddress::findOne($sd['emp_master_emp_address_id'])->emp_padd . " " . $add_c . " " . $add_s . " " . $add_co . "</td>";
         } else {
             echo "<td>&nbsp;</td>";
         }
     } else {
         if ($s == 'emp_joining_date') {
             $jdate = EmpInfo::findOne($sd['emp_master_emp_info_id'])->{$s};
             echo "<td class='text-center'>" . date('d-m-Y', strtotime($jdate)) . "</td>";
         } else {
             if ($s == 'emp_dob') {
                 $bdate = EmpInfo::findOne($sd['emp_master_emp_info_id'])->{$s};
                 echo "<td class='text-center'>" . date('d-m-Y', strtotime($bdate)) . "</td>";
             $add_c = City::findOne(StuAddress::findOne($sd['stu_master_stu_address_id'])->stu_padd_city);
             if (!empty($add_c)) {
                 $add_city_c = $add_c->city_name . " , ";
             } else {
                 $add_city_c = '';
             }
         } else {
             $add_c = '';
         }
         if (!empty(StuAddress::findOne($sd['stu_master_stu_address_id'])->stu_padd_state)) {
             $add_s = State::findOne(StuAddress::findOne($sd['stu_master_stu_address_id'])->stu_padd_state)->state_name . ", ";
         } else {
             $add_s = '';
         }
         if (!empty(StuAddress::findOne($sd['stu_master_stu_address_id'])->stu_padd_country)) {
             $add_co = Country::findOne(StuAddress::findOne($sd['stu_master_stu_address_id'])->stu_padd_country)->country_name;
         } else {
             $add_co = '';
         }
         echo "<td style='text-align:center; width:400px;'>" . StuAddress::findOne($sd['stu_master_stu_address_id'])->stu_padd . $add_city_c . " " . $add_s . " " . $add_co . "</td>";
     } else {
         echo "<td>&nbsp;</td>";
     }
 } else {
     if ($s == 'city') {
         if ($sd['stu_master_stu_address_id'] != 0) {
             $add = StuAddress::findOne($sd['stu_master_stu_address_id']);
             if (!empty($add)) {
                 $city = City::findOne($add->stu_cadd_city);
             }
             if (!empty($add->stu_cadd_city)) {
Beispiel #8
0
<?php

use yii\jui\DatePicker;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
$model = \app\models\Country::findOne('CN');
echo DatePicker::widget(['model' => $model, 'attribute' => 'population', 'language' => 'zh-CN', 'dateFormat' => 'yyyy-MM-dd']);
echo DatePicker::widget(['language' => 'zh-CN', 'name' => 'country', 'dateFormat' => 'php:Y_m_d', 'clientOptions' => ['dateFormat' => 'php:m/d/Y']]);
$form = ActiveForm::begin(['id' => 'login-form']);
echo $form->field($model, 'code');
echo $form->field($model, 'name')->passwordInput();
?>

    <div class="form-group">
        <?php 
echo Html::submitButton('登录');
?>
    </div>

<?php 
ActiveForm::end();
?>
<hr>
<?php 
echo Html::a('vcxvxcvxcv', \yii\helpers\Url::to(['site/dd', 'id' => 1212]));
echo '<pre>';
print_r(Yii::$app->request->cookies->getValue('language'));
echo '</pre>';
echo \yii\widgets\Menu::widget(['activateItems' => false, 'firstItemCssClass' => 'post', 'lastItemCssClass' => 'popp', 'options' => ['style' => 'background: grey'], 'items' => [['label' => 'Home', 'url' => ['site/index'], 'items' => [['label' => 'New Arrivals', 'url' => ['product/index', 'tag' => 'new']], ['label' => 'Most Popular', 'url' => ['product/index', 'tag' => 'popular']]]], ['label' => 'Products', 'url' => ['product/index']], ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest]]]);
 /**
  * Deletes an existing CountryData model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionBackup($id)
 {
     // $this->findModel($id)->delete();
     $arr = array('WB-各国电力普及率-20151206.xls', 'WB-各国能源进口比例-20151206.xls', 'WB-各国清洁能源消费比例-20151206.xls', 'WB-各国人均能源使用量-20151206.xls', 'WB-各国人均碳排放量-20151206.xls', 'WB-各国人口总量-20151206.xls', 'WB-各国碳排放总量-20151206.xls', 'WB-各国GDP-20151206.xls');
     $key_arr = array('indicator_code', 'indicator_name', 'source_note', 'source_organization');
     $file = Yii::$app->basePath . '/data/' . $file_path;
     $PHPExcel = \PHPExcel_IOFactory::load($file);
     $sheet = $PHPExcel->getSheet(3);
     // 读取第一個工作表(编号从 0 开始)
     $highestRow = $sheet->getHighestRow();
     // 取得总行数
     $highestColumm = $sheet->getHighestColumn();
     // 取得总列数
     $years = 2014 - 1965 + 1;
     for ($row = 5; $row <= $highestRow; $row++) {
         $org = array();
         $country = null;
         $data_key = null;
         $data_value = null;
         $flag = true;
         // $row = 5;
         for ($column = 0; $column <= 3; $column++) {
             $column_name = \PHPExcel_Cell::stringFromColumnIndex($column);
             $val = (string) $sheet->getCell($column_name . $row)->getValue();
             $key = $key_arr[$column] ? $key_arr[$column] : null;
             if ($column == 1) {
                 if ($val == "US") {
                     $val == "United States";
                 }
                 if ($val == "Trinidad & Tobago") {
                     $val == "Trinidad and Tobago";
                 }
                 $country_model = Country::findOne(['name_english' => $val]);
                 if (!isset($country_model->id)) {
                     $country = null;
                     continue;
                 } else {
                     $country = $country_model->id;
                 }
             }
             if ($column >= 4 && trim($val) != "" && $country) {
                 $model = new CountryData();
                 $model->country_id = $country;
                 $model->data_key = "oil_production";
                 $model->data_value = $val;
                 $y = 1965 + $column - 4;
                 $model->data_version = (string) $y;
                 var_dump($model->attributes);
                 // $model->save();
             }
         }
     }
     return $this->redirect(['index']);
 }
Beispiel #10
0
 public function actionGetCitiesFromYndex()
 {
     set_time_limit(300);
     $url = "https://pogoda.yandex.ru/static/cities.xml";
     $dom = new \DomDocument();
     $dom->load($url);
     $cities = $dom->getElementsByTagName("city");
     foreach ($cities as $city) {
         $i = 0;
         $country = $city->getAttribute('country');
         $countryIs = Country::findOne(['name' => $country]);
         if ($countryIs) {
             $country_id = $countryIs->id;
         } else {
             $country_id = 0;
         }
         $cityNew = new City();
         $cityNew->yndid = $city->getAttribute('id');
         $cityNew->name = $city->textContent;
         $cityNew->part = $city->getAttribute('part');
         $cityNew->region = $city->getAttribute('region');
         $cityNew->country_id = $country_id;
         $cityNew->save(false);
         echo $i . "  " . $cityNew->name;
     }
 }
Beispiel #11
0
 public function validateCountryId($attribute, $params)
 {
     $id = (int) $this->countryId;
     if ($id == 0) {
         $this->addError('countryName', "Неправильно указана страна.");
     } elseif (!Country::findOne($id)) {
         // TODO добавить отправку уведомления об ошибке с данными на email разработчику
         $this->addError('countryName', "Указанная страна не существует.");
     }
 }