本文整理汇总了PHP中app\models\Author::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Author::find方法的具体用法?PHP Author::find怎么用?PHP Author::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Author
的用法示例。
在下文中一共展示了Author::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionShow
/**
* Показывает контент
* @return string
* @TODO Нужно предусмотреть возможность вывода разного контента, привязаного к одной категории
*
*/
public function actionShow()
{
$this->cat_id = Yii::$app->getRequest()->getQueryParam('id') ? Yii::$app->getRequest()->getQueryParam('id') : null;
$cat_obg = Categories::find()->where('id = ' . $this->cat_id)->one();
$allContent = Articles::find()->where('cat_id = ' . $this->cat_id)->all();
$allArticlesForPager = Articles::find()->where(['cat_id' => $this->cat_id]);
$countQueryCont = clone $allArticlesForPager;
$pagesGlobal = new Pagination(['totalCount' => $countQueryCont->count(), 'pageSize' => 1, 'forcePageParam' => false, 'pageSizeParam' => false]);
$artPages = $allArticlesForPager->offset($pagesGlobal->offset)->limit($pagesGlobal->limit)->all();
foreach ($allContent as $article) {
//var_dump($this->cat_id);
$this->article_id = $article->id;
$article = Articles::findOne($this->article_id);
$allArticles = ArticlesContent::find()->where(['articles_id' => $this->article_id])->orderBy(['id' => SORT_DESC]);
//var_dump($allArticles); exit;
$countQuery = clone $allArticles;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => isset($article->onepages) ? $article->onepages : 0, 'forcePageParam' => false, 'pageSizeParam' => false]);
$models = $allArticles->offset($pages->offset)->limit($pages->limit)->all();
$this->source = Source::find()->where(['id' => $models[0]->source_id])->one()->title;
$this->author = Author::find()->where(['id' => Source::find()->where(['id' => $models[0]->source_id])->one()->author_id])->one()->name;
$this->articles[] = ['article' => $article, 'contents' => $models, 'pages' => $pages, 'source' => $this->source, 'author' => $this->author];
}
//var_dump($this->articles); exit;
return $this->renderPartial($cat_obg->action, ['articles' => $this->articles, 'cat' => $this->cat_id, 'pagesGlobal' => $pagesGlobal, 'artPages' => $artPages, 'cat_obg' => $cat_obg]);
}
示例2: search
public function search($params)
{
$query = Author::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
$query->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}
示例3: actionIndex
/**
* @param string $q
* @return array
*/
public function actionIndex($q = null)
{
Yii::$app->getResponse()->format = Response::FORMAT_JSON;
$model = Author::find()->limit(10);
if (!is_null($q)) {
$model->where(['or', ['like', 'firstname', $q], ['like', 'lastname', $q]]);
}
return ['results' => $model->all()];
}
示例4: actionIndex
public function actionIndex()
{
$searchModel = new SearchBook();
$author = new Author();
$author->surname = '';
$authors_data = $author->find()->select(['id', "name"])->all();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'author' => $author, 'authors_data' => $authors_data]);
}
示例5: actionUpdate
/**
* Updates an existing Book model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$authors = \app\models\Author::find()->all();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('update', ['model' => $model, 'authors' => $authors]);
}
}
示例6: runComplexQuery
public function runComplexQuery($i)
{
Author::find()->from('Author a')->where('a.id > :id OR (a.firstName || a.lastName) = :name', ['id' => $this->authors[array_rand($this->authors)]->id, 'name' => 'John Doe'])->count('a.id');
// $authors = $this->em->createQuery(
// 'SELECT count(a.id) AS num FROM Author a WHERE a.id > ?1 OR CONCAT(a.firstName, a.lastName) = ?2'
// )->setParameter(1, $this->authors[array_rand($this->authors)]->id)
// ->setParameter(2, 'John Doe')
// ->setMaxResults(1)
// ->getSingleScalarResult();
}
示例7: actionUpdate
public function actionUpdate($id)
{
$book = Book::findOne(['id' => $id]);
$filtredModel = Yii::$app->request->get('filtredModel');
if (Yii::$app->request->isPost) {
$book->load(Yii::$app->request->post());
$book->save();
$this->redirect(Url::to(array_merge(['books/index'], $filtredModel)));
}
return $this->render('update', ['book' => $book, 'authors' => Author::find()->all(), 'Book' => $filtredModel]);
}
示例8: actionUpdate
/**
* Updates an existing Book model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$file = UploadedFile::getInstance($model, 'preview');
if ($model->upload($file) && $model->save()) {
return $this->redirect(Url::previous());
}
}
return $this->render('update', ['model' => $model, 'authors' => Author::find()->all()]);
}
示例9: getListAuthor
/**
* Возвращает массив авторов вида: [id=>{firsname lastname},...]
*
* @return array
*/
public static function getListAuthor()
{
$authors = Author::find()->select(['id', 'firstname', 'lastname'])->all();
$result = [];
/**
* @var Author $author
*/
foreach ($authors as $author) {
$result[$author->id] = $author->getFullName();
}
return $result;
}
示例10: actionUpdate
/**
* Updates an existing Book model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$authors = Author::find()->asArray()->all();
for ($i = 1; $i <= Author::find()->count(); $i++) {
$authors_array[$i] = $authors[$i - 1]['firstname'] . ' ' . $authors[$i - 1]['lastname'];
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', ['model' => $model, 'authors_array' => $authors_array]);
}
}
示例11: actionUpdate
/**
* Updates an existing Book model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if (Yii::$app->request->isPost) {
$model->load(Yii::$app->request->post());
$model->imageFile = UploadedFile::getInstance($model, 'preview');
$model->uploadFile();
$model->save(false);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', ['model' => $model, 'authors' => (new AuthorCollection())->createEntity(Author::find()->all(), true)]);
}
}
示例12: actionShow
/**
* Показываем контент
* @param $id
* @return string
*/
public function actionShow($id)
{
$article = Articles::findOne($id);
$comment = new Comments();
$this->title = $article->title;
$allArticles = ArticlesContent::find()->where(['articles_id' => $id]);
//var_dump($allArticles); exit;
$countQuery = clone $allArticles;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => isset($article->onepages) ? $article->onepages : 0, 'forcePageParam' => false, 'pageSizeParam' => false]);
$models = $allArticles->offset($pages->offset)->limit($pages->limit)->all();
$this->source = Source::find()->where(['id' => $models[0]->source_id])->one()->title;
$this->author = Author::find()->where(['id' => Source::find()->where(['id' => $models[0]->source_id])->one()->author_id])->one()->name;
return $this->render('view', ['articles' => $allArticles, 'contents' => $models, 'pages' => $pages, 'title' => $this->title, 'source' => $this->source, 'author' => $this->author, 'comment' => $comment]);
}
示例13: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Author::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]);
$query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname]);
return $dataProvider;
}
示例14: actionCreate
/**
* Создание автораа
* @return string
*/
public function actionCreate()
{
$model = new Author();
if ($model->load(Yii::$app->request->post())) {
$model->name = Yii::$app->request->post('Author')['name'];
$model->status = Yii::$app->request->post('Author')['status'];
$model->description = Yii::$app->request->post('Author')['description'];
$model->country_id = Yii::$app->request->post('Author')['country_id'];
$model->save(false);
$authors = Author::find();
$dataProvider = new ActiveDataProvider(['query' => $authors]);
return $this->redirect(Url::toRoute('author/index'));
} else {
return $this->render('_form', ['model' => $model]);
}
}
示例15: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Author::find();
// add conditions that should always apply here
$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;
}
// grid filtering conditions
$query->andFilterWhere(['author_id' => $this->author_id, 'birth' => $this->birth]);
$query->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name]);
return $dataProvider;
}