本文整理汇总了PHP中app\models\Book::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::find方法的具体用法?PHP Book::find怎么用?PHP Book::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Book
的用法示例。
在下文中一共展示了Book::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
/**
* Creates data provider instance with search query applied
* @param array $params
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Book::find();
$query->joinWith('author');
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
$dataProvider->sort->attributes['author.name'] = ['asc' => ['{{%author.name}}' => SORT_ASC], 'desc' => ['{{%author.name}}' => SORT_DESC]];
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
if ($this->author_id) {
$query->andFilterWhere(['{{%book.author_id}}' => $this->author_id]);
}
if ($this->name) {
$query->andFilterWhere(['like', '{{%book.name}}', $this->name]);
}
if ($this->date_from) {
$query->andWhere('{{%book.date}} > :date_from', ['date_from' => strtotime($this->date_from)]);
}
if ($this->date_to) {
$query->andWhere('{{%book.date}} < :date_to', ['date_to' => strtotime($this->date_to)]);
}
// $query
// ->andFilterWhere(['{{%book.author_id}}' => $this->author_id])
// ->andFilterWhere(['like', '{{%book.name}}', $this->name])
// ->andWhere('{{%book.date}} > :date_from', ['date_from' => strtotime($this->date_from)])
// ->andWhere('{{%book.date}} < :date_to', ['date_to' => strtotime($this->date_to)]);
return $dataProvider;
}
示例2: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
Book::find($id)->delete();
\Session::flash('flash_message', 'Deleted Successfully!');
\Session::flash('flash_message_level', 'success');
return Redirect::back();
}
示例3: actionUpdate
/**
* Страница изменения информации книги.
*
* @param int $id
* @return string|\yii\web\Response
*/
public function actionUpdate($id)
{
/** @var Book $modelBook */
$modelBook = Book::find()->with(['authors', 'tags'])->where(['id' => $id])->one();
$this->_saveBook($modelBook);
return $this->render('/back/book/update', ['modelBook' => $modelBook]);
}
示例4: loadModel
private function loadModel($id)
{
$model = Book::find($id)->one();
if (!$model) {
throw new HttpException(404, 'Not Found');
}
return $model;
}
示例5: runJoinSearch
public function runJoinSearch($i)
{
$book = \app\models\Book::find()->from('Book b')->with('author')->where('b.title = ?', ['Hello' . $i])->limit(1)->scalar();
// $book = $this->em->createQuery(
// 'SELECT b, a FROM Book b JOIN b.author a WHERE b.title = ?1'
// )->setParameter(1, 'Hello' . $i)
// ->setMaxResults(1)
// ->getScalarResult();
}
示例6: coverStore
public function coverStore(Request $request, $id)
{
$book = Book::find($id);
if (Gate::denies('manageBook', $book)) {
abort(403, 'voce não é o dono desse livro');
}
$bookService = app()->make(BookService::class);
$bookService->storeCover($book, $request->file('file'));
}
示例7: runJoinSearch
public function runJoinSearch($i)
{
$book = Book::find()->from('Book b')->with('author')->where('b.title = :t', [':t' => 'Hello' . $i])->one();
// $book = $this->em->createQuery(
// 'SELECT b, a FROM Book b JOIN b.author a WHERE b.title = ?1'
// )->setParameter(1, 'Hello' . $i)
// ->setMaxResults(1)
// ->getResult();
}
示例8: searchAction
/**
* @Get("/search/{name}")
*
* @param $name
*
* @return Response
*/
public function searchAction($name)
{
/** @var Book[] $books */
$books = Book::find(["name LIKE '%{$name}%'"]);
$response = new Response();
$data = [];
foreach ($books as $book) {
$data[] = ['id' => $book->getId(), 'name' => $book->getName()];
}
return $response->setJsonContent($data);
}
示例9: actionIndex
public function actionIndex()
{
$dataProvider = new ArrayDataProvider(['allModels' => Book::find()->orderBy('rank')->limit(3)->asArray()->all()]);
//$test = Book::getDb()->cache(function($db){
// Book::find()->orderBy('rank');
//});
//$result = $db->cache(function ($db) {
// return $db->createCommand('SELECT * FROM user WHERE id=4')->queryOne();
//});
return $this->render('index', ['dataProvider' => $dataProvider]);
}
示例10: downloadSample
/**
* Download book by id.
*
* @return Response
*/
public function downloadSample($idbook)
{
$fileBooks = Book::find($idbook)->filebooks()->where('is_sample', 1)->get();
if (count($fileBooks) >= 1) {
$files = array();
foreach ($fileBooks as $key => $value) {
array_push($files, base_path() . '/book/' . $idbook . '/' . $value->link);
}
Zipper::make(base_path() . '/book/' . $idbook . '/sample.zip')->add($files);
}
$pathDownload = base_path() . "/book/" . $idbook . '/sample.zip';
return response()->download($pathDownload);
}
示例11: actionIndex
public function actionIndex()
{
$books = Book::find()->all();
$data = array();
foreach ($books as $book) {
$dataBook = array();
$dataBook['label'] = substr($book->name, 0, strpos($book->name, ':'));
$listChapter = Chapter::find()->where(['book_id' => $book->id])->all();
$dataBook['content'] = $this->renderPartial('list', ['book' => $book, 'listChapter' => $listChapter]);
$data[] = $dataBook;
}
return $this->render('index', ['data' => $data]);
}
示例12: search
public function search()
{
$query = Book::find();
$this->addCondition($query, 'title', true);
$this->addCondition($query, 'author_id');
if ($this->date_created_from) {
$query->andWhere(['>=', 'date_created', $this->date_created_from]);
}
if ($this->date_created_to) {
$query->andWhere(['<=', 'date_created', $this->date_created_to]);
}
return new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20]]);
}
示例13: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Book::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$query->joinWith(['author']);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['>', 'date', $this->published_from])->andFilterWhere(['<', 'date', $this->published_to])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['=', 'author_id', $this->author_id]);
return $dataProvider;
}
示例14: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Book::find()->joinWith('author')->asArray();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'date_update' => $this->date_update, 'date_create' => $this->date_create, 'date' => $this->date, 'author_id' => $this->author_id]);
$query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'preview', $this->preview]);
return $dataProvider;
}
示例15: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Book::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'published_date' => $this->published_date]);
$query->andFilterWhere(['like', 'title', $this->title]);
return $dataProvider;
}