本文整理汇总了PHP中app\models\Book::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::load方法的具体用法?PHP Book::load怎么用?PHP Book::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Book
的用法示例。
在下文中一共展示了Book::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
$returning = function () use($model) {
$authors = Author::find()->all();
$dropDownSearchItems = ArrayHelper::map($authors, 'id', 'lastname');
return $this->render('create', ['model' => $model, 'dropDownAuthorItems' => $dropDownSearchItems]);
};
if ($model->load(Yii::$app->request->post())) {
$model->image = UploadedFile::getInstance($model, 'image');
if (is_object($model->image)) {
$preview = 'preview_img/' . uniqid() . '_' . $model->image->name;
$model->image->saveAs($preview);
$model->image = null;
$model->preview = '/' . $preview;
}
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $returning();
}
} else {
return $returning();
}
}
示例2: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例3: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
$authors = \app\models\Author::find()->all();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model, 'authors' => $authors]);
}
}
示例4: actionCreate
public function actionCreate()
{
$book = new Book();
if (Yii::$app->request->isPost) {
$book->load(Yii::$app->request->post());
$book->save();
$this->redirect(Url::to(['books/index']));
}
return $this->render('create', ['book' => $book, 'authors' => Author::find()->all()]);
}
示例5: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
\yii\caching\TagDependency::invalidate(Yii::$app->cache, 'books');
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例6: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
if ($model->load(Yii::$app->request->post())) {
$model->previewFile = UploadedFile::getInstance($model, 'previewFile');
if ($model->upload() && $model->save()) {
return $this->redirect(['index']);
}
}
return $this->render('create', ['model' => $model]);
}
示例7: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
$searchModel = new BookSearch();
$authors = $searchModel->getAuthors()->all();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'authors' => $authors]);
}
}
示例8: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
if ($model->load(Yii::$app->request->post())) {
$file = UploadedFile::getInstance($model, 'preview');
if ($model->upload($file) && $model->save()) {
return $this->redirect(Url::previous());
}
}
return $this->render('create', ['model' => $model, 'authors' => Author::find()->all()]);
}
示例9: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
if (Yii::$app->request->isPost) {
$model->load(Yii::$app->request->post());
$model->imageFile = UploadedFile::getInstance($model, 'preview');
$model->uploadFile();
$model->save(false);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'authors' => (new AuthorCollection())->createEntity(Author::find()->all(), true)]);
}
}
示例10: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
$authors = Author::find()->asArray()->all();
for ($i = 1; $i <= Author::find()->count(); $i++) {
$authors_array[$i] = $authors[$i - 1]['firstname'] . ' ' . $authors[$i - 1]['lastname'];
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'authors_array' => $authors_array]);
}
}
示例11: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
if ($model->load(Yii::$app->request->post())) {
$model->bookImage = UploadedFile::getInstance($model, 'bookImage');
if ($model->validate() && $model->save()) {
if (Url::previous()) {
return $this->redirect(Url::previous());
}
return $this->redirect(Url::toRoute('index'));
}
}
return $this->render('create', ['model' => $model]);
}
示例12: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
if ($model->load(Yii::$app->request->post())) {
$image = UploadedFile::getInstance($model, 'preview');
$temp_var = explode(".", $image->name);
$ext = end($temp_var);
$model->date = Book::getIntDate($model->date);
$model->preview = Yii::$app->security->generateRandomString() . ".{$ext}";
$path = Yii::$app->params['uploadPath'] . $model->preview;
$image->saveAs($path);
$model->save();
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model, 'author' => Author::find()->all()]);
}
}
示例13: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$image = UploadedFile::getInstance($model, 'imageFile');
if (!empty($image)) {
$model->image = Yii::$app->security->generateRandomString() . '.' . $image->extension;
$path = Yii::$app->basePath . '/' . Book::IMAGES_DIRECTORY . $model->image;
$model->save();
$image->saveAs($path);
} else {
$model->save();
}
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例14: save
/**
* @param Book $model
* @param $template
* @return array|Response
*/
protected function save($model, $template)
{
if ($model->load(Yii::$app->request->post())) {
if ($model->validate()) {
if ($model->save(false)) {
$params = ArrayHelper::merge(['index'], $this->getSession()->get(self::SESSION_PARAMS));
return $this->redirect($params);
} else {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
} else {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
} else {
return $this->{$this->getCurrentRender()}($template, ['model' => $model, 'authors' => $this->getAuthors()]);
}
}
示例15: actionCreate
/**
* Creates a new Book model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Book();
$time = time();
$model->date_create = date('Y-m-d H:i:s', $time);
$authorData = Author::find()->all();
$authorsList = [];
foreach ($authorData as $author) {
$authorsList[$author->id] = $author->firstname . ' ' . $author->lastname;
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($model->preview = UploadedFile::getInstance($model, 'preview')) {
$path = Yii::$app->basePath . Yii::$app->params['uploadPath'] . $model->preview;
$model->preview->saveAs($path);
$model->preview = Yii::$app->params['uploadPath'] . $model->preview;
}
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'authors' => $authorsList]);
}
}