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