本文整理匯總了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]);
}
}