本文整理汇总了PHP中app\models\Books::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Books::load方法的具体用法?PHP Books::load怎么用?PHP Books::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Books
的用法示例。
在下文中一共展示了Books::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
{
if (Yii::$app->user->isGuest) {
Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-danger'], 'body' => Yii::t('app', 'You are not authorized for this action.')]);
return $this->redirect(Url::toRoute('/site/login'));
}
$model = new Books();
if ($model->load(Yii::$app->request->post())) {
$image = UploadedFile::getInstance($model, 'preview');
if (!empty($image)) {
$dir = Yii::getAlias('@app/web/img');
$uploaded = $image->saveAs($dir . '/' . $image->name);
$model->preview = $image->name;
}
$model->date_create = self::getCurrentDateTime();
$model->date_update = self::getCurrentDateTime();
if ($model->validate() && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-danger'], 'body' => Yii::t('app', 'Error. Incorrect data')]);
return $this->redirect(['index']);
}
} else {
return $this->render('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();
$session = Yii::$app->session;
if (strripos($_SERVER['HTTP_REFERER'], 'BooksSearch') || strripos($_SERVER['HTTP_REFERER'], 'sort')) {
$session->set('redirect_param', $_SERVER['HTTP_REFERER']);
}
if ($model->load(Yii::$app->request->post())) {
$file_image = UploadedFile::getInstance($model, 'image');
if ($file_image && $file_image->tempName) {
$model->image = $file_image;
if ($model->validate(['image'])) {
$base_patch = 'uploads/';
$dir = Yii::getAlias('../web/' . $base_patch);
$fileName = $model->image->baseName . '.' . $model->image->extension;
$model->image->saveAs($dir . $fileName);
$model->image = $fileName;
$model->image = $dir . $fileName;
$model->preview = $base_patch . $fileName;
}
}
if ($model->save()) {
return isset($session['redirect_param']) ? $this->redirect($session->get('redirect_param')) : $this->redirect(['index']);
//return $this->redirect(['view', 'id' => $model->id]);
}
} else {
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())) {
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]);
}
}
示例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->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', ['model' => $model]);
}
示例5: 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->save()) {
return $this->redirect(['index']);
} else {
return $this->renderAjax('create', ['model' => $model]);
}
}
示例6: 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->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'authors' => $this->getAuthorsArray(Authors::find()->all())]);
}
}
示例7: 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->uploadImage();
return $model->save() ? $this->redirect(['index']) : var_dump($model);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例8: 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();
$model->date_create = $model->date_update = date('Y-m-d H:i:s');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(isset($_POST['referer']) ? $_POST['referer'] : '/');
} else {
return $this->render('create', ['model' => $model]);
}
}
示例9: actionCreate
/**
* Creates a new Books model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$book = new Books();
$author = new Authors();
if ($book->load(Yii::$app->request->post()) && $book->save()) {
return $this->redirect(['view', 'id' => $book->id]);
} else {
return $this->render('create', ['model' => $book, 'author' => $author]);
}
}
示例10: actionCreate
/**
* Creates a new Books model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($closeOnLoad = false)
{
$model = new Books();
$data = $this->filterData(Yii::$app->request->post());
if ($model->load($data) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id, 'closeOnLoad' => $closeOnLoad]);
} else {
return $this->render('create', ['model' => $model, 'authors' => $this->getAuthorsForDropDownList()]);
}
}
示例11: 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();
$model->scenario = 'create';
if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) {
if ($this->loadPreview($model) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('create', ['model' => $model]);
}
示例12: actionCreate
public function actionCreate()
{
$model = new Books();
if ($model->load(Yii::$app->request->post())) {
$model->uploadImage();
$model->date_create = date('Y-m-d');
$model->date_update = date('Y-m-d');
$model->save();
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例13: 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->upload()) {
//var_dump(Yii::$app->request->post());die();
if ($model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', ['authors' => Authors::find()->all(), 'model' => $model]);
}
} else {
return $this->render('create', ['authors' => Authors::find()->all(), 'model' => $model]);
}
}
示例14: 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();
$model_b_a_rel = new BookAuthorRel();
$authorsArr = Authors::authorArr();
if ($model->load(Yii::$app->request->post()) && $model_b_a_rel->load(Yii::$app->request->post())) {
$model->save();
$model_b_a_rel->b_id = $model->id;
$model_b_a_rel->saveMultiple();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'model_b_a_rel' => $model_b_a_rel, 'authorsArr' => $authorsArr]);
}
}
示例15: 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();
$modelAuthorsBooks = new AuthorsBooks();
$data = Yii::$app->request->post();
if ($model->load($data) && $model->save()) {
$modelAuthorsBooks->a_id = $data['AuthorsBooks']['a_id'][0];
$modelAuthorsBooks->b_id = $model->id;
if ($modelAuthorsBooks->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('create', ['model' => $model, 'modelAuthorsBooks' => $modelAuthorsBooks]);
}
}