本文整理汇总了PHP中Books::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Books::validate方法的具体用法?PHP Books::validate怎么用?PHP Books::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Books
的用法示例。
在下文中一共展示了Books::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionAdd
public function actionAdd()
{
Yii::app()->getClientScript()->registerCoreScript('jquery');
Yii::app()->getClientScript()->registerCoreScript('jquery.ui');
$cs = Yii::app()->clientScript;
$cs->registerCssFile('/js/datepicker/css/' . 'datepicker.css');
$cs->registerScriptFile('/js/' . 'books.js');
//
$book = new Books();
$command = Yii::app()->db->createCommand();
if (isset($_POST['Books'])) {
$book->attributes = $_POST['Books'];
if ($book->validate()) {
$book->save();
if (isset($_POST['add_auth']) && !empty($_POST['add_auth'])) {
$criteria = new CDbCriteria();
$criteria->compare('lastname', $_POST['add_auth']);
$add_author = Authors::model()->find($criteria);
//If author exists
if (!empty($add_author)) {
//insert link book-author to link table
$command->insert('lt_books_authors', array('author_id' => $add_author->id, 'book_id' => $book->id));
}
}
$this->actionIndex();
return true;
}
}
$this->render('edit', array('model' => $book));
}
示例2: actionAddNewBook
public function actionAddNewBook()
{
$transaction = Yii::app()->db->beginTransaction();
try {
$book_model = new Books();
$book_attributes = $_POST['Books'];
$book_attributes['creation_date'] = date('Y-m-d H:i:s');
$book_model->attributes = $book_attributes;
if ($book_model->validate()) {
if ($book_model->save()) {
$last_insert_book_id = $book_model->id;
$relation_array = array();
foreach ($_POST['author_list'] as $author) {
$relation_array[] = array('book_id' => $last_insert_book_id, 'author_id' => $author);
}
$builder = Yii::app()->db->schema->commandBuilder;
$command = $builder->createMultipleInsertCommand('authors_books_relation', $relation_array);
$command->execute();
$transaction->commit();
Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, 'Новая книга добавлена');
$this->redirect(array('library/tabs&tab_id=books'));
}
}
} catch (CDbException $e) {
$transaction->rollback();
}
}