コード例 #1
0
ファイル: ProfileController.php プロジェクト: Ravend6/nishant
 public function actionCityList($id)
 {
     if ($countryCities = Country::findOne($id)) {
         foreach ($countryCities->cities as $city) {
             echo "<option value='" . $city->id . "'>" . $city->name . "</option>";
         }
     } else {
         echo "<option> - </option>";
     }
 }
コード例 #2
0
 public function actionEntry()
 {
     $model = new EntryForm();
     // 获取 country 表的所有行并以 name 排序
     $countries = Country::find()->orderBy('name')->all();
     //print_r($countries);
     // 获取主键为 “US” 的行
     $country = Country::findOne('US');
     // 输出 “United States”
     //echo $country->name;
     // 修改 name 为 “U.S.A.” 并在数据库中保存更改
     //$country->name = 'U.S.A.';
     //$country->save();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         // 验证 $model 收到的数据
         // 做些有意义的事 ...
         return $this->render('entry-confirm', ['model' => $model, 'countries' => $countries]);
     } else {
         // 无论是初始化显示还是数据验证错误
         //$this->renderFile('@app/views/myform/myform_header.php');
         //echo $this->render('myformheader');
         return $this->render('entry', ['model' => $model, 'countries' => $countries]);
     }
 }
コード例 #3
0
ファイル: index.php プロジェクト: Ravend6/nishant
:</b> <?php 
    echo $profile->last_name;
    ?>
</p>
                    <p><b><?php 
    echo $profile->getAttributeLabel('gender');
    ?>
:</b> <?php 
    echo $profile->gender ? 'Male' : 'Female';
    ?>
</p>
                    <p><b><?php 
    echo $profile->getAttributeLabel('country_id');
    ?>
:</b> <?php 
    echo Country::findOne($profile->country_id)->name;
    ?>
</p>
                    <p><b><?php 
    echo $profile->getAttributeLabel('city_id');
    ?>
:</b> <?php 
    echo City::findOne($profile->city_id)->name;
    ?>
</p>
                    <p><b><?php 
    echo $profile->getAttributeLabel('address');
    ?>
:</b> <?php 
    echo $profile->address;
    ?>
コード例 #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 string $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.');
     }
 }