当前位置: 首页>>代码示例>>PHP>>正文


PHP Books::validate方法代码示例

本文整理汇总了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));
 }
开发者ID:alex-sparrow,项目名称:library_test,代码行数:30,代码来源:BooksController.php

示例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();
     }
 }
开发者ID:maxim-bondarenko,项目名称:library,代码行数:27,代码来源:LibraryController.php


注:本文中的Books::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。