本文整理汇总了PHP中app\models\Article::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::find方法的具体用法?PHP Article::find怎么用?PHP Article::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Article
的用法示例。
在下文中一共展示了Article::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionView
/**
* Displays a single Article model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$this->layout = 'main2';
$model = $this->findModel($id);
$articles = Article::find()->where(['status' => 'ACTIVE', 'type' => 'NEWS', 'category' => $model->category])->limit(4)->all();
return $this->render('view', ['model' => $model, 'articles' => $articles]);
}
示例2: actionIndex
public function actionIndex()
{
$query = Article::find();
$pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $query->count()]);
$articles = $query->orderBy('id')->offset($pagination->offset)->limit($pagination->limit)->all();
return $this->render('index', ['articles' => $articles, 'pagination' => $pagination]);
}
示例3: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id = null)
{
//返回/resource/view/nweaver/commuity下的create.blade.php页面
//编辑文章文章
$article = Article::find($id);
return view('nweaver.commuity.edit', compact('article'));
}
示例4: actionCreate
/**
* Creates a new Visa model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($num = 1)
{
$this->layout = "main";
$model = new Visa();
$article = Article::find()->where(['type' => 103])->one();
$visaDetails = [];
$numApply = isset($_POST['Visa']['numapply']) ? $_POST['Visa']['numapply'] : $num;
for ($i = 0; $i < $numApply; $i++) {
$visaDetails[] = new Visadetail();
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$visaId = $model->id;
if (isset($_POST['Visadetail'])) {
foreach ($_POST['Visadetail'] as $index => $arr) {
foreach ($arr as $i => $val) {
$visaDetails[$index - 1][$i] = $val;
}
$visaDetails[$index - 1]['id_visa'] = $visaId;
}
foreach ($visaDetails as $visaDetail) {
if ($visaDetail->save()) {
}
}
Yii::$app->mailer->compose('@app/views/mail/mail-layout', ['model' => $model, 'visaDetails' => $visaDetails])->setFrom($model->email)->setTo('duytu2005@gmail.com')->setSubject('Book tour')->send();
return $this->render('success', ['model' => $model, 'visaDetails' => $visaDetails, 'article' => $article]);
}
} else {
if (Yii::$app->request->isAjax) {
return $this->renderAjax('create', ['model' => $model, 'article' => $article, 'visaDetails' => $visaDetails]);
} else {
return $this->render('create', ['model' => $model, 'visaDetails' => $visaDetails, 'article' => $article]);
}
}
}
示例5: destroy
public function destroy($id)
{
$article = Article::find($id);
$article->delete();
Notification::success('The article was deleted.');
return Redirect::route('admin.articles.index');
}
示例6: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$data['article'] = Article::find($id);
ArticleStatus::update_view_number($id);
$this->setCommonData();
return view('website.article', $data);
}
示例7: findArticle
/**
* @param $slug
* @return Article
*/
protected function findArticle($slug)
{
if (($model = Article::find()->where(['slug' => $slug])->one()) !== null) {
return $model;
} else {
return false;
}
}
示例8: actionView
public function actionView($id)
{
$model = Article::find()->published()->with('author')->andWhere(['id' => $id])->one();
if (!$model) {
throw new NotFoundHttpException();
}
return $this->render('view', ['model' => $model]);
}
示例9: actionArticle
public function actionArticle($year, $month, $day, $id)
{
$item = Article::find(['id_string' => $id, 'date' => $year . $month . $day]);
if (is_null($item)) {
throw new Exception('Нет такой статьи');
}
$item->incViewCounter();
return $this->render(['item' => $item]);
}
示例10: delete
public function delete(Article $article, $id)
{
$data = $article->find($id);
if (!$data) {
return response()->json(['error' => 'data not found'], 404);
}
$data->delete();
return response()->json(200);
}
示例11: actionViewall
public function actionViewall($cid = 2)
{
$query = Article::find()->where(['cid' => $cid, 'published' => 1]);
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count()]);
$models = $query->offset($pages->offset)->limit($pages->limit)->orderBy('ordering')->all();
$cat = \app\models\Categories::findOne($cid);
return $this->render('viewall', ['model' => $models, 'cat' => $cat, 'pages' => $pages]);
}
示例12: search
/**
* Creates data provider instance with search query applied
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Article::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'slug' => $this->slug, 'author_id' => $this->author_id, 'category_id' => $this->category_id, 'updater_id' => $this->updater_id, 'status' => $this->status, 'published_at' => $this->published_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
$query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'body', $this->body]);
return $dataProvider;
}
示例13: delete
public function delete($id)
{
$id = intval($id);
$articleInstance = Article::find($id);
if (!$articleInstance->trashed()) {
$articleInstance->delete();
return Redirect::back()->withResult('operation complete');
} else {
return Redirect::back()->withResult('this article has been deleted already.');
}
}
示例14: postSimpan
public function postSimpan($value = '')
{
$model = new Article();
if (Input::get('id') > 0) {
$model = Article::find(Input::get('id'));
}
$model->title = Input::get('title');
$model->description = Input::get('description');
$model->save();
return Redirect::to('article');
}
示例15: actionSubscribe
/**
* AJAX
* Добавляет site_update
* Делает рассылку
*
* @param integer $id - идентификатор новости
*
* @return string
*/
public function actionSubscribe($id)
{
$item = Article::find($id);
if (is_null($item)) {
return self::jsonError(101, 'Не найдена статья');
}
Subscribe::add($item);
SiteUpdate::add($item);
$item->update(['is_added_site_update' => 1]);
return self::jsonSuccess();
}