本文整理汇总了PHP中app\models\Country::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Country::load方法的具体用法?PHP Country::load怎么用?PHP Country::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Country
的用法示例。
在下文中一共展示了Country::load方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Создание контента
* @return string
*/
public function actionCreate()
{
$model = new Country();
$uploadImg = new UploadForm();
if (Yii::$app->request->isPost) {
$uploadImg->img = UploadedFile::getInstance($uploadImg, 'img');
if ($uploadImg->img && $uploadImg->validate()) {
$uploadImg->img->saveAs('uploads/icoflags/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension);
} else {
print_r($uploadImg->getErrors());
}
}
if ($model->load(Yii::$app->request->post())) {
$model->name = Yii::$app->request->post('Country')['name'];
$model->iso_code = Yii::$app->request->post('Country')['iso_code'];
$model->soc_abrev = Yii::$app->request->post('Country')['soc_abrev'];
$model->soccer_code = Yii::$app->request->post('Country')['soccer_code'];
if (isset($uploadImg->img)) {
$model->icon = Url::base() . 'uploads/icoflags/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension;
}
$model->save(false);
return $this->redirect(Url::toRoute('countries/index'));
} else {
return $this->render('_form', ['model' => $model, 'uploadImg' => $uploadImg]);
}
}
示例2: actionCreate
/**
* Creates a new Country model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Country();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->country_id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例3: actionUpdate
/**
* Updates an existing Country model.
* If update is successful, the browser will be redirected to the 'update' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id = null)
{
if ($id) {
$model = $this->findModel($id);
} else {
$model = new Country();
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('success', __('Your changes have been saved successfully.'));
return $this->redirect(['index']);
} else {
return $this->renderAjax('update', ['model' => $model]);
}
}
示例4: getAll
public static function getAll()
{
if (empty(self::$list)) {
if ($file = file_get_contents(Yii::$app->basePath . '/web/data/countries.json')) {
$list = Json::decode($file);
if (!empty($list['countries'])) {
foreach ($list['countries'] as $data) {
$country = new Country();
$country->load(['Country' => $data]);
self::$list[$data['code']] = $country;
}
}
}
}
return self::$list;
}
示例5: actionCreate
/**
* Creates a new Country model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Country();
$searchModel = new CountrySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if ($model->load(Yii::$app->request->post())) {
if (Yii::$app->request->isAjax) {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
$model->attributes = $_POST['Country'];
$model->created_by = Yii::$app->getid->getId();
$model->created_at = new \yii\db\Expression('NOW()');
if ($model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
}
} else {
return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
}
}