本文整理汇总了PHP中app\models\Book::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::setAttributes方法的具体用法?PHP Book::setAttributes怎么用?PHP Book::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Book
的用法示例。
在下文中一共展示了Book::setAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderList
private function renderList()
{
$model = new Book();
$searchParams = Yii::$app->request->get('Book');
if ($searchParams) {
$model->setAttributes($searchParams, false);
$model->dateFrom = $searchParams['dateFrom'];
$model->dateTo = $searchParams['dateTo'];
}
$provider = $model->search();
return $this->render('index', ['provider' => $provider, 'model' => $model]);
}
示例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 (!empty(Yii::$app->request->post())) {
$model->setAttributes(Yii::$app->request->post());
$model->authors = Yii::$app->request->post('authors');
$model->tags = Yii::$app->request->post('tags');
$model->formats = Yii::$app->request->post('formats');
if ($model->save()) {
$bookFiles = \Yii::$app->basePath . '/files/tmp/book-form/1/';
$imgFile = \Yii::$app->basePath . '/web/image/book/tmp/1/';
$this->copyFiles($bookFiles, \Yii::$app->basePath . '/files/books/' . $model->id . '/');
$this->copyFiles($imgFile, \Yii::$app->basePath . '/web/image/book/' . $model->id . '/');
$this->deleteFiles(\Yii::$app->basePath . '/files/tmp/book-form/1/');
$this->deleteFiles(\Yii::$app->basePath . '/web/image/book/tmp/1/');
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('create', ['model' => $model]);
}