本文整理汇总了PHP中app\models\Books::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Books::find方法的具体用法?PHP Books::find怎么用?PHP Books::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Books
的用法示例。
在下文中一共展示了Books::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIndex
/**
* Lists all Books models.
* @return mixed
*/
public function actionIndex()
{
//Yii::$app->user->isGuest;
$authors = Authors::find()->all();
$get = Yii::$app->request->get()['Filter'];
$dataProvider;
$query = Books::find();
if (isset(Yii::$app->request->get()['Filter'])) {
if ($get["author_id"] != 0) {
$query->andWhere(['author_id' => $get["author_id"]]);
}
if ($get["title"] != "") {
//$query->andWhere(['name' => $post["title"]]);
$query->andWhere(['like', 'name', $get["title"]]);
}
if ($get["dateMin"] != "") {
$query->andWhere('date > :dateMin', [':dateMin' => $get["dateMin"]]);
}
if ($get["dateMax"] != "") {
$query->andWhere('date < :dateMax', [':dateMax' => $get["dateMax"]]);
}
}
$dataProvider = new ActiveDataProvider(['query' => $query]);
return $this->render('index', ['dataProvider' => $dataProvider, 'authors' => $authors]);
}
示例2: search
public function search($params)
{
Yii::$app->session['BooksSearch'] = $params;
$query = Books::find();
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]);
$dataProvider->setSort(['attributes' => ['id', 'name', 'preview', 'authorfullname' => ['asc' => ['authors.firstname' => SORT_ASC, 'authors.lasttname' => SORT_ASC], 'desc' => ['authors.firstname' => SORT_DESC, 'authors.lasttname' => SORT_DESC], 'label' => Yii::t('app', 'Author'), 'default' => SORT_ASC], 'date', 'date_create']]);
$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');
$query->joinWith(['author']);
return $dataProvider;
}
$query->andFilterWhere(['like', 'name', $this->name]);
if ($this->date_from) {
$query->andFilterWhere(['>=', 'date', $this->date_from]);
}
if ($this->date_to) {
$query->andFilterWhere(['<=', 'date', $this->date_to]);
}
if ($this->author_id) {
$query->andFilterWhere(['author_id' => $this->author_id]);
}
$query->joinWith(['author']);
return $dataProvider;
}
示例3: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Books::find()->with('authors');
$dataProvider = new ActiveDataProvider(['query' => $query]);
$dataProvider->setSort(['attributes' => ['id', 'name', 'authorFullName' => ['asc' => ['authors.firstname' => SORT_ASC, 'authors.lastname' => SORT_ASC], 'desc' => ['authors.firstname' => SORT_DESC, 'authors.lastname' => SORT_DESC], 'label' => 'Автор'], 'date_update', 'date_create', 'date']]);
$this->load($params);
// валидация
if (!$this->validate()) {
$query->joinWith(['authors']);
return $dataProvider;
}
// Фильтр по Автору
$query->joinWith(['authors' => function ($q) {
$this->authorFullName = trim($this->authorFullName);
if ($this->authorFullName) {
$Asearch = str_replace(" ", "|", $this->authorFullName);
$q->where('`authors`.`firstname` RLIKE "' . $Asearch . '" ' . 'OR `authors`.`lastname` RLIKE "' . $Asearch . '"');
}
}]);
/* $query->andFilterWhere([
'name' => $this->name,
'authors.firstname' => $this->authorFullName,
]);*/
$query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['BETWEEN', 'date', $this->date_1, $this->date_2]);
return $dataProvider;
}
示例4: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Books::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;
}
if ($this->author_id) {
$query->andFilterWhere(['author_id' => $this->author_id]);
}
if ($this->date_from) {
if ($this->date_till) {
$query->andFilterWhere(['date' => ['between', $this->date_from, $this->date_till]]);
} else {
$query->andFilterWhere(['>=', 'date', $this->date_from]);
}
} elseif ($this->date_till) {
$query->andFilterWhere(['<=', 'date', $this->date_till]);
}
if ($this->name) {
$query->andFilterWhere(['like', 'name', $this->name]);
}
return $dataProvider;
}
示例5: actionIndex
/**
* Lists all Books models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new BooksSearch();
// $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider = new ActiveDataProvider(['query' => Books::find()]);
return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]);
}
示例6: getSearchQuery
/**
* Get query for book search
* @return [QueryInterface]
*/
public function getSearchQuery()
{
$query = Books::find();
//Author
$query = $query->filterWhere(['author_id' => $this->author_id]);
//Name
if (!empty($this->name)) {
$query = $query->andWhere(['like', 'name', $this->name]);
}
//Date
if ($this->firstTimestamp != 0 && $this->secondTimestamp != 0) {
if ($this->firstTimestamp == $this->secondTimestamp) {
$query = $query->andWhere(['=', 'date', $this->firstTimestamp]);
} else {
$query = $query->andWhere(['between', 'date', $this->firstTimestamp, $this->secondTimestamp]);
}
} else {
if ($this->firstTimestamp != 0) {
$query = $query->andWhere(['>=', 'date', $this->firstTimestamp]);
} else {
if ($this->secondTimestamp != 0) {
$query = $query->andWhere(['<=', 'date', $this->secondTimestamp]);
}
}
}
return $query;
}
示例7: actionRemove
public function actionRemove($id)
{
if (Yii::$app->request->isAjax) {
$model = Books::find()->where(['id' => $id])->one();
$model->delete();
Yii::$app->response->format = Response::FORMAT_JSON;
return array('result' => true);
}
return $this->redirect('index.php?r=site%2Fbooks');
}
示例8: actionIndex
public function actionIndex($order = false, $order_type = false, $search_key = false)
{
$order_field = $order ? $order : 'id';
$order_type = $order_type ? $order_type == 'DESC' ? SORT_DESC : SORT_ASC : SORT_ASC;
if ($search_key) {
$query = Books::find()->andFilterWhere(['or', ['like', 'author', $search_key], ['like', 'name', $search_key]]);
} else {
$query = Books::find();
}
return new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => [$order_field => $order_type]]]);
}
示例9: getAuthorBooks
public static function getAuthorBooks($author_id, $return_count = true)
{
$author_id = (int) $author_id;
$data = Books::find()->where('authors LIKE "%,' . $author_id . '" OR authors LIKE "%' . $author_id . '," OR authors LIKE "' . $author_id . '"');
if ($return_count) {
$data = (int) $data->count();
} else {
$data = $data->all();
}
return $data;
}
示例10: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Books::find()->addSelect([$this->tableName() . ".*", "CONCAT(authors.firstname, ' ', authors.lastname) AS author_fullname"])->joinWith(['author']);
$dataProvider = new ActiveDataProvider(['query' => $query]);
$dataProvider->sort->attributes['author'] = ['asc' => ['authors.firstname' => SORT_ASC], 'desc' => ['authors.firstname' => SORT_DESC]];
$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(['like', 'books.name', $this->name]);
// поиск по дате от/до
if (!empty($this->book_date_from) and !empty($this->book_date_to)) {
// конвертирую в корректный формат времени и добавляю четкие временные границы
$book_date_from = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->book_date_from), 'dd-MM-yyyy 00:00:00');
$book_date_to = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->book_date_to), 'dd-MM-yyyy 23:59:59');
$book_date_from = Yii::$app->formatter->asTimestamp($book_date_from);
$book_date_to = Yii::$app->formatter->asTimestamp($book_date_to);
$query->andFilterWhere(['between', 'books.date', $book_date_from, $book_date_to]);
}
// поиск по автору
if ($this->author_fullname == 7 or in_array(trim(mb_strtolower($this->author)), array('без', 'без привязки', 'без привязки к автору'))) {
// для книг без привязки к автору - из books
$query->andFilterWhere(['=', 'author_id', 0]);
} else {
// из authors
$query->andFilterWhere(['like', 'authors.firstname', $this->author]);
$query->andFilterWhere(['=', 'authors.id', $this->author_fullname]);
}
/////////////////////// доп параметры для filterModel (если раскомменчены filterModel и Pjax в books/index.php)
$query->andFilterWhere(['=', 'books.id', $this->id])->andFilterWhere(['like', 'books.preview', $this->preview]);
// дата Выхода книги
if (!empty($this->date)) {
// конвертирую в корректный формат времени и добавляю четкие временные границы
$book_date_from = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->date), 'dd-MM-yyyy 00:00:00');
$book_date_to = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->date), 'dd-MM-yyyy 23:59:59');
$book_date_from = Yii::$app->formatter->asTimestamp($book_date_from);
$book_date_to = Yii::$app->formatter->asTimestamp($book_date_to);
$query->andFilterWhere(['between', 'books.date', $book_date_from, $book_date_to]);
}
// дата Добавления книги
if (!empty($this->date_create)) {
// конвертирую в корректный формат времени и добавляю четкие временные границы
$book_date_from = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->date_create), 'dd-MM-yyyy 00:00:00');
$book_date_to = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->date_create), 'dd-MM-yyyy 23:59:59');
$book_date_from = Yii::$app->formatter->asTimestamp($book_date_from);
$book_date_to = Yii::$app->formatter->asTimestamp($book_date_to);
$query->andFilterWhere(['between', 'books.date_create', $book_date_from, $book_date_to]);
}
///////////////////
return $dataProvider;
}
示例11: search
public function search($params)
{
$query = Books::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
$query->andFilterWhere(['author_id' => $this->author_id]);
$query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['<=', 'date', $this->date_to])->andFilterWhere(['>=', 'date', $this->date_from]);
return $dataProvider;
}
示例12: dashboard
public function dashboard()
{
// Check Author authentication Session
if (!Auth::check('default')) {
return $this->redirect('Authors::login');
}
// Retrieve current Author ID
$author_id = Auth::check('default')->data['id'];
// Retrieve Books from the current Author
$conditions = array('Books.author_id' => Auth::check('default')->data['id']);
$books = Books::find('all', compact('conditions'));
return compact('books', 'author_id');
}
示例13: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Books::find()->joinWith('bookAuthors')->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]);
$query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'issue_year', $this->issue_year])->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'annotation', $this->annotation]);
return $dataProvider;
}
示例14: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Books::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, 'author_id' => $this->author_id != 0 ? $this->author_id : ''])->andFilterWhere(['between', 'date', $this->date_start, $this->date_end]);
$query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'preview', $this->preview]);
return $dataProvider;
}
示例15: delete
public function delete()
{
// Check Author authentication Session
if (!Auth::check('default')) {
return $this->redirect('Authors::login');
}
$book = Books::find($this->request->id);
if ($book && $book->delete()) {
Session::write('message', 'Book deleted');
$this->redirect(array('Authors::dashboard'));
} else {
Session::write('message', 'Book can not be deleted');
}
}