本文整理汇总了PHP中common\models\Article类的典型用法代码示例。如果您正苦于以下问题:PHP Article类的具体用法?PHP Article怎么用?PHP Article使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Article类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insert
/**
* 将文章插入数据库
* @param $title
* @param $content
* @param $publish_at
* @param $tag
* @return bool
*/
public static function insert($title, $content, $publish_at, $tag = '')
{
//插入标签(搜索的分类)
$article = new Article();
$article->title = $title;
$article->content = $content;
$article->author = 'yang';
$article->status = Article::STATUS_GATHER;
$article->publish_at = $publish_at;
$res = $article->save(false);
if ($tag) {
try {
$tagModel = Tag::find()->where(['name' => $tag])->one();
if (!$tagModel) {
$tagModel = new Tag();
$tagModel->name = $tag;
$tagModel->article_count = 0;
$tagModel->save(false);
}
$articleTag = new ArticleTag();
$articleTag->article_id = $article->id;
$articleTag->tag_id = $tagModel->id;
$articleTag->save(false);
} catch (\Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
}
return $res ? true : false;
}
示例2: actionView
public function actionView($id)
{
$article = Article::findOne($id);
$comment = new Comment();
$comments = $article->comments;
return $this->render("view", ["article" => $article, "comment" => $comment, "comments" => $comments]);
}
示例3: setStatus
/**
* 是否显示状态修改
* @param $article_id
* @param int $status
* @return bool|int
*/
public function setStatus($article_id, $status = 1)
{
if (!in_array($status, [0, 1])) {
return false;
}
return Article::updateAll(['status' => $status], 'article_id = :article_id', [':article_id' => $article_id]);
}
示例4: actionView
public function actionView($id)
{
$this->view_data['article'] = $article = Article::find()->where("id = {$id}")->asArray()->one();
//获取这篇文章的所有留言
$this->view_data['comments'] = Article::getComments($article['id']);
return $this->render('view', $this->view_data);
}
示例5: actionAddStars
public function actionAddStars($id)
{
if (\Yii::$app->request->isAjax) {
$model = Article::findOne($id);
$model->addStars();
return json_encode(1);
}
}
示例6: findModel
/**
* Finds the Article model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Article the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Article::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例7: actionView
/**
* @param $slug
* @return string
* @throws NotFoundHttpException
*/
public function actionView($slug)
{
$model = Article::find()->published()->andWhere(['slug' => $slug])->one();
if (!$model) {
throw new NotFoundHttpException();
}
$viewFile = $model->view ?: 'view';
return $this->render($viewFile, ['model' => $model]);
}
示例8: actionDetail
public function actionDetail($id)
{
if (!($article = Article::findOne($id))) {
throw new NotFoundHttpException('ID 为 ' . $id . ' 的文章没有找到');
}
//文章标签
$tags = $article->getArticleTag();
//相关文章
return $this->render('detail', ['article' => $article, 'tags' => $tags]);
}
示例9: cache404Page
/**
* 生成 404 静态页面
* @author gaoqing
* @date 2016-04-20
* @param string $cacheKey 缓存的唯一标识
* @return boolean$generateFlag是否生成成功
*/
public static function cache404Page($cacheKey, $param = [], $forceCache = false)
{
$generateFlag = false;
$frontend = \Yii::getAlias('@frontend');
$page404FileName = $frontend . '/web/404.shtml';
if (!file_exists($page404FileName)) {
$forceCache = true;
}
if ($forceCache) {
$view = "404";
//获取最新的资讯文章
$article = new Article();
$where = ' status=20';
$order = ' articleid DESC';
$lastestNews = $article->List_Articles($where, $order, 5, 0);
//获取 疾病健康 文章
$darticle = new \common\models\disease\Article();
$lastestJibingArticle = $darticle->getLatestArticle(5, 0);
//精彩问答
$ask = new Ask();
$where1 = ' 1';
$order1 = ' id DESC';
$lastestAsk = $ask->getList($where1, $order1, 5, 0);
//字母部分
$letters = range('A', 'Z');
$condition = array('typeid' => array(0, 2, 3, 4, 5, 6, 7, 8, 9));
$rand_words = KeyWords::getCacheRandWords(100, $condition);
//热门疾病、热门部位
$commonDisDep = CacheHelper::getCache('frontend_article_detail_rmksbw_404', []);
$params = ['lastestNews' => $lastestNews, 'lastestJibingArticle' => $lastestJibingArticle, 'lastestAsk' => $lastestAsk, 'letters' => $letters, 'rand_words' => $rand_words, 'commonDisDep' => $commonDisDep, 'searchurl' => 'http://www.9939.com/zhuanti/'];
$controller = new BaseController('base404', null);
$controller->id = "base404";
$page404FilePath = $frontend . '/views/site';
$controller->viewPath = $page404FilePath;
$page404 = $controller->renderPartial($view, $params);
if (isset($page404) && !empty($page404)) {
if (file_put_contents($page404FileName, $page404)) {
$generateFlag = true;
}
}
}
return $generateFlag;
}
示例10: findModel
/**
* Finds the ArticleDownload model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return ArticleDownload the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
$ArticleDownload = ArticleDownload::findOne($id);
$Article = Article::findOne($id);
if ($ArticleDownload !== null && $Article !== null) {
return ['ArticleDownload' => $ArticleDownload, 'Article' => $Article];
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例11: actionDelete
/**
* Deletes an existing ArticleCategory model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$articleModel = Article::find()->andWhere(['category_id' => $id])->one();
if (null === $articleModel) {
$this->findModel($id)->delete();
} else {
Yii::$app->session->setFlash('alert', ['body' => \Yii::t('backend', 'Can not delete category #' . $id . '. It used in other table. Change category for article #' . $articleModel->id . ' before delete.'), 'options' => ['class' => 'alert-error']]);
}
return $this->redirect(['index']);
}
示例12: getMetaTags
public static function getMetaTags()
{
$tags = [];
$locale = null;
$arr = self::parseUrl(Yii::$app->request->pathInfo);
if (!empty($arr[0]) and !empty($arr[1]) and !empty($arr[2]) and !empty($arr[3])) {
$shortLocale = $arr[0];
$controller = $arr[1];
$action = $arr[2];
$slug = $arr[3];
foreach (Yii::$app->params['availableLocales'] as $k => $v) {
if ($shortLocale == explode('-', $k)[0]) {
$locale = $k;
}
}
switch ($controller) {
case 'page':
$model = self::find()->published()->andWhere(['slug' => $slug, 'locale' => $locale])->one();
break;
case 'article':
$model = Article::find()->published()->andWhere(['slug' => $slug, 'locale' => $locale])->one();
break;
case 'promo':
//$model = Promo::find()->published()->andWhere(['slug' => $slug, 'locale' => $locale])->one();
break;
case 'project':
$model = Project::find()->published()->andWhere(['slug' => $slug, 'locale' => $locale])->one();
break;
}
//hardcore :) json to array
if (!empty($model) and !empty($model->head)) {
$arr = json_decode($model->head, true);
foreach ($arr as $key => $value) {
foreach ($value as $key2 => $value2) {
//custom meta tag
if (4 == count($value2)) {
$value2 = array_values($value2);
$value2 = [$value2[0] => $value2[1], $value2[2] => $value2[3]];
}
$tags[] = $value2;
}
}
}
if (empty($model)) {
throw new NotFoundHttpException('The requested page does not exist.');
}
if (!empty($tags[0]) and !empty($tags[0]['name']) and 'title' == !empty($tags[0]['name']) and !empty($tags[0]['content'])) {
Yii::$app->view->title = $tags[0]['content'];
} else {
Yii::$app->view->title = $model->title;
}
}
return $tags;
}
示例13: search
/**
* Creates data provider instance with search query applied
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Article::find()->published();
$dataProvider = new ActiveDataProvider(['query' => $query]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'slug' => $this->slug, 'category_id' => $this->category_id]);
$query->andFilterWhere(['like', 'title', $this->title]);
return $dataProvider;
}
示例14: 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', 'weight', $this->weight])->andFilterWhere(['like', 'body', $this->body]);
return $dataProvider;
}
示例15: actionTag
/**
* Lists the Article models in a specific category $slug.
*
* @param $slug
* @return mixed
*/
public function actionTag($slug)
{
$model = Tag::find()->andWhere(['slug' => $slug])->one();
if (!$model) {
throw new NotFoundHttpException(Yii::t('frontend', 'Page not found.'));
}
$query = Article::find()->with('category')->joinWith('tags')->where('{{%tag}}.slug = :slug', [':slug' => $slug])->published();
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => 10]]);
$dataProvider->sort = ['defaultOrder' => ['created_at' => SORT_DESC]];
return $this->render('tag', ['model' => $model, 'dataProvider' => $dataProvider, 'menuItems' => self::getMenuItems()]);
}