本文整理汇总了PHP中Books::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Books::model方法的具体用法?PHP Books::model怎么用?PHP Books::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Books
的用法示例。
在下文中一共展示了Books::model方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionRemove
public function actionRemove($b_id)
{
Yii::app()->db->createCommand()->delete('lt_books_authors', 'book_id=' . $b_id);
//removing records from link table
Books::model()->deleteByPk($b_id);
$this->actionIndex();
}
示例2: actionIndex
public function actionIndex()
{
$book_model = Books::model();
$authors_model = Authors::model();
$params = array('book_model' => $book_model, 'authors_model' => $authors_model);
$this->render('report', $params);
}
示例3: getBooksFromFiltr
private function getBooksFromFiltr($arg)
{
//прием аргументов фильтрации, снова повторюсь сори что без валидации
$authors = $arg['authors'];
$genre = $arg['genre'];
$from_year = $arg['from_year'];
$to_year = $arg['to_year'];
//все индификаторы книг что прошли фильтр по автору и по жанрам
$book_author = BookAuthor::model()->with('books')->findAllByAttributes($authors);
$book_gerne = BookGenre::model()->with('books')->findAllByAttributes($genre);
foreach ($book_author as $class) {
$flag[$class->bid] = true;
//методом флажок - выясню есть ли в другом масиве теже bid
}
foreach ($book_gerne as $class) {
if ($flag[$class->bid]) {
$bids[] = $class->bid;
}
//если была создана ячека флажка, то значит что первый фильтр bid прошел
}
//выборка всех книг по фильтрованым индификаторам
$books = Books::model()->findAllByAttributes(array('bid' => $bids), 'year>=' . $from_year . ' AND year<=' . $to_year);
//хочу свормировать красивый масив без ячеек, которые сотворил yii
$result = array();
$i = 0;
foreach ($books as $book) {
$result[$i]['authors'] = $this->getAuthorsFromBid($book->bid);
$result[$i]['genres'] = $this->getGenresFromBid($book->bid);
$result[$i]['book']['bid'] = $book->bid;
$result[$i]['book']['name'] = $book->name;
$result[$i]['book']['year'] = $book->year;
$i = $i + 1;
}
return $result;
}
示例4: actionSearch
public function actionSearch()
{
$model = Books::model();
$params = array('result' => $model->searchPhrase($_POST['search_field']));
$this->render('search', $params);
//echo '<pre>'; print_r($_POST); echo'</pre>';
}
示例5: actionAbout
public function actionAbout($id)
{
$book = Books::model()->findByPk($id);
if (!empty($book)) {
$comments = BooksComments::model()->findAll(array('condition' => 'book_id = :bookId', 'params' => array(':bookId' => $book->id), 'order' => 'id DESC', 'limit' => '10'));
$this->render('about', array('book' => $book, 'comments' => $comments));
} else {
$this->redirect(array('index/index'));
}
}
示例6: loadModel
public function loadModel($id = null, $new = false)
{
if ($this->_book === null) {
if ($new) {
return $this->_book = new Books();
}
$this->_book = Books::model()->findByPk($_GET['id']);
if ($this->_book === null) {
throw new CHttpException(404, 'Sorry! There is no such book.');
}
}
return $this->_book;
}
示例7: setBookRate
/**
* @property Books $book
*/
public static function setBookRate($id, $percent)
{
$percent = $percent > 100 ? 100 : $percent < 0 ? 0 : $percent;
$rate = self::model()->findByAttributes(array('book_id' => $id, 'user_id' => Yii::app()->user->id));
if (empty($rate)) {
$rate = new BookRate();
$rate->book_id = $id;
$rate->user_id = Yii::app()->user->id;
}
$rate->rate = $percent;
$rate->save();
$book = Books::model()->findByPk($id);
if (!empty($book)) {
$book->updateRate();
}
return $book->rate;
}
示例8: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer $id the ID of the model to be loaded
* @return Books the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model = Books::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例9: actionIndex
public function actionIndex()
{
$books = Books::model()->findAll(array('order' => 'RAND()', 'limit' => 10));
$this->render("index", array('books' => $books));
}
示例10: detailBook
public function detailBook($book_id)
{
$data = Books::model()->findByAttributes(array('id' => $book_id));
return $data;
}
示例11: actionUpdateLibraryData
public function actionUpdateLibraryData($id)
{
$params = $_POST['ReadersBooksRelation'];
$book_id = $_POST['books_list'];
$params['book_id'] = $book_id;
$params['reader_id'] = $_POST['reader_list'];
$model = new ReadersBooksRelation();
$last_count = ($res = $model->getDataRelationById($id)) ? (int) $params['count_books'] - (int) $res->count_books : $params['count_books'];
$free_book = Books::model()->isFreeBook($book_id, $last_count);
$message = '';
$color = '';
if (!$free_book) {
$message = 'Все экземпляры книги находятся у читателей!!!';
$color = TbHtml::ALERT_COLOR_WARNING;
} else {
$model->deleteByPk($id);
$model->attributes = $params;
if ($model->validate()) {
if ($model->save()) {
$message = 'Обновление Прошло успешно';
$color = TbHtml::ALERT_COLOR_SUCCESS;
}
}
}
Yii::app()->user->setFlash($color, $message);
$this->redirect(array('library/tabs&tab_id=library'));
}
示例12: actionSearch
public function actionSearch()
{
$request = Yii::app()->request;
try {
$query = $request->getQuery('query');
$limit = $request->getQuery('limit');
$offset = $request->getQuery('offset');
$data = Books::model()->searchBooks($query, $limit, $offset);
ResponseHelper::JsonReturnSuccess($data, "Success");
} catch (Exception $ex) {
var_dump($ex->getMessage());
}
}