本文整理汇总了PHP中app\models\Project::loadDefaultValues方法的典型用法代码示例。如果您正苦于以下问题:PHP Project::loadDefaultValues方法的具体用法?PHP Project::loadDefaultValues怎么用?PHP Project::loadDefaultValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Project
的用法示例。
在下文中一共展示了Project::loadDefaultValues方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionEdit
/**
* 配置项目
*
* @param $projectId
* @return string
* @throws \Exception
*/
public function actionEdit($projectId = null)
{
if ($projectId) {
$project = $this->findModel($projectId);
} else {
$project = new Project();
$project->loadDefaultValues();
}
if (\Yii::$app->request->getIsPost() && $project->load(Yii::$app->request->post())) {
$project->user_id = $this->uid;
if ($project->save()) {
// 保存ansible需要的hosts文件
$this->_saveAnsibleHosts($project);
$this->redirect('@web/conf/');
}
}
return $this->render('edit', ['conf' => $project]);
}
示例2: actionCreate
/**
* Creates a new Project model.
* If creation is successful, the browser will be redirected to the 'overview' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Project();
$model->loadDefaultValues();
if ($model->load(Yii::$app->request->post())) {
$image = UploadedFile::getInstance($model, 'image');
if (!is_null($image)) {
// store the source file name
$model->logoname = $image->name;
$ext = end(explode(".", $image->name));
// generate a unique file name
$model->logo = Yii::$app->security->generateRandomString() . ".{$ext}";
$path = Yii::$app->basePath . '/web/uploads/' . $model->logo;
}
if ($model->save()) {
if (!is_null($image)) {
$image->saveAs($path);
}
$member = new Member();
$member->setAttribute('project_id', $model->id);
$member->setAttribute('user_id', Yii::$app->user->id);
$member->setAttribute('role', 'Administrator');
$member->save();
return $this->redirect(['overview', 'identifier' => $model->identifier]);
} else {
Yii::$app->getSession()->setFlash('danger', Yii::t('app', 'Something went wrong and the settings was not saved.'));
}
} else {
return $this->render('create', ['model' => $model]);
}
}