当前位置: 首页>>代码示例>>PHP>>正文


PHP Country::findOne方法代码示例

本文整理汇总了PHP中app\models\Country::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Country::findOne方法的具体用法?PHP Country::findOne怎么用?PHP Country::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Country的用法示例。


在下文中一共展示了Country::findOne方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: findModel

 /**
  * 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.');
     }
 }
开发者ID:vsguts,项目名称:crm,代码行数:15,代码来源:CountryController.php

示例2: loadModel

 /**
  * Загружает запись модели текущего контроллера по айдишнику
  * @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;
 }
开发者ID:roman1970,项目名称:lis,代码行数:14,代码来源:CountriesController.php

示例3: actionCountry

 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';
 }
开发者ID:xiaosongluffy,项目名称:yiilearn,代码行数:9,代码来源:SiteController.php

示例4: actionIndex

 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]);
 }
开发者ID:KozakSystem,项目名称:framework,代码行数:10,代码来源:CountryController.php

示例5: actionTest

 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');
 }
开发者ID:study-code,项目名称:yii2,代码行数:54,代码来源:CountryController.php

示例6: date

     }
 } 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>";
开发者ID:EduSec,项目名称:EduSec,代码行数:31,代码来源:emp_info_report.php

示例7:

             $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)) {
开发者ID:aoopvn,项目名称:EduSec4.0.0,代码行数:31,代码来源:stu_info_report_excel.php

示例8:

<?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]]]);
开发者ID:GarenGoh,项目名称:yii,代码行数:29,代码来源:index.php

示例9: actionBackup

 /**
  * 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']);
 }
开发者ID:sanmaowang,项目名称:energy-app,代码行数:60,代码来源:CountryDataController.php

示例10: actionGetCitiesFromYndex

 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;
     }
 }
开发者ID:roman1970,项目名称:lis,代码行数:26,代码来源:WeatherController.php

示例11: validateCountryId

 public function validateCountryId($attribute, $params)
 {
     $id = (int) $this->countryId;
     if ($id == 0) {
         $this->addError('countryName', "Неправильно указана страна.");
     } elseif (!Country::findOne($id)) {
         // TODO добавить отправку уведомления об ошибке с данными на email разработчику
         $this->addError('countryName', "Указанная страна не существует.");
     }
 }
开发者ID:Sywooch,项目名称:TailorPlace,代码行数:10,代码来源:StudioForm.php


注:本文中的app\models\Country::findOne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。