本文整理汇总了PHP中app\models\Books::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Books::validate方法的具体用法?PHP Books::validate怎么用?PHP Books::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Books
的用法示例。
在下文中一共展示了Books::validate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new Books model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Books();
if ($model->load(Yii::$app->request->post())) {
if (!$model->validate()) {
yii::$app->session->setFlash('create_bad', yii::t('app', 'New book not has been created'));
return $this->redirect(['index']);
}
// upload new preview
$model->upload_preview = UploadedFile::getInstance($model, 'upload_preview');
if ($model->upload_preview) {
if (($model->upload_preview->type == 'image/jpeg' or $model->upload_preview->type == 'image/png' or $model->upload_preview->type == 'image/gif' or $model->upload_preview->type == 'image/svg+xml') and $model->upload_preview->size < 999999) {
$preview_name_arr = preg_replace("~[ :-]~", "_", explode(".", $model->upload_preview->name));
$preview_name = $preview_name_arr[0] . '__' . time() . "." . $model->upload_preview->extension;
$model->upload_preview->saveAs('img/small/' . $preview_name, false);
$model->upload_preview->saveAs('img/original/' . $preview_name);
$model->preview = $preview_name;
} else {
yii::$app->session->setFlash('upload_preview_bad', yii::t('app', 'Preview not uploaded: error type or big size'));
}
}
// возвращаю к формату согласно БД
$model->date_create = time();
$model->date_update = time();
$model->date = Yii::$app->formatter->asTimestamp($model->date);
$model->save();
yii::$app->session->setFlash('create_ok', yii::t('app', 'New book - <i>{name}</i> - has been successfully created', array('name' => $model->name)));
return $this->redirect(Url::previous());
} else {
return $this->renderAjax('create', ['model' => $model]);
}
}
示例2: actionCreate
/**
* Creates a new Books model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Books();
if ($model->load(Yii::$app->request->post())) {
$upload_file = $model->uploadFile();
var_dump($model->validate());
if ($model->validate()) {
if ($model->save()) {
if ($upload_file !== false) {
$path = $model->getUploadedFile();
$upload_file->saveAs($path);
}
return $this->redirect(['index']);
}
}
}
return $this->render('create', ['model' => $model]);
}
示例3: actionCreate
/**
* Creates a new Books model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Books();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($this->saveUpload($model)) {
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('create', ['model' => $model]);
}
示例4: actionCreate
/**
* Creates a new Books model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Books();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$file = UploadedFile::getInstance($model, 'image');
$model->image = $file;
// Если изображение выбрано, загрузить его
if (!empty($model->image)) {
$filename = uniqid();
$model->image = $file;
$model->preview = $filename . "." . $model->image->getExtension();
if ($model->save()) {
$file->saveAs($model->getUplDir() . $filename . "." . $model->image->getExtension());
return $this->redirect(["index"]);
}
} else {
if ($model->save()) {
return $this->redirect(["index"]);
}
}
}
return $this->render('create', ['model' => $model]);
}