Exemple #1
0
 /**
  * Показывает контент
  * @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]);
 }
 /**
  * 一对多关系
  *  动态属性(还可以在一对一关系里面使用)
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  * A hasMany B
  * demo : user hasMay article
  */
 public function articleUser()
 {
     //一条语句
     $user = Articles::find(1)->user;
     //多条语句
     $obj = new Articles();
     $article = $obj->find(1);
     $user = $article->user;
     debug($user);
     //动态属性
     debug($article->user->username);
     return view('index');
 }
 public function actionView($id)
 {
     $article = Articles::find()->where(['id' => $id])->one();
     $article->view = $article->view + 1;
     $article->save(false);
     $popularArticle = Articles::find()->orderBy('view DESC')->limit(5)->all();
     $discussedArticle = Articles::find()->joinWith('comments', true, 'RIGHT JOIN')->groupBy('comments.article_id')->orderBy('count(comments.article_id) DESC')->limit(5)->all();
     $modelCategory = Category::find()->all();
     $model = $this->findModel($id);
     $comments = Comments::find()->with('user')->where(['article_id' => $id, 'enable' => 1])->all();
     $user = User::find()->where(['id' => $model->author_id])->one();
     return $this->render('view', ['model' => $model, 'modelCategory' => $modelCategory, 'user' => $user, 'comments' => $comments, 'popularArticle' => $popularArticle, 'discussedArticle' => $discussedArticle]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Articles::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', 'name', $this->name])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $modelCategory = Category::find()->all();
     $modelArticle = Articles::find()->with('articleImg')->orderBy('id DESC')->all();
     $popularArticle = Articles::find()->orderBy('view DESC')->limit(5)->all();
     $discussedArticle = Articles::find()->joinWith('comments', true, 'RIGHT JOIN')->groupBy('comments.article_id')->orderBy('count(comments.article_id) DESC')->limit(5)->all();
     $arrUser = array();
     $userName = array();
     foreach ($modelArticle as $article) {
         $arrUser[] = $article['author_id'];
     }
     foreach ($arrUser as $i => $user) {
         $userModel = User::find()->where(['id' => $user])->all();
         $userName[] = $userModel[0];
     }
     return $this->render('index', ['modelCategory' => $modelCategory, 'modelArticle' => $modelArticle, 'userName' => $userName, 'popularArticle' => $popularArticle, 'discussedArticle' => $discussedArticle]);
 }
Exemple #6
0
 /**
  * @return string
  */
 public function actionIndex()
 {
     $uploadFile = new UploadForm();
     //var_dump($_POST);
     if (Yii::$app->request->isPost) {
         $uploadFile->file = UploadedFile::getInstance($uploadFile, 'file');
         // var_dump($uploadFile->file); exit;
         if ($uploadFile->file && $uploadFile->validate()) {
             $uploadFile->file->saveAs('uploads/' . Yii::$app->translater->translit($uploadFile->file->baseName) . '.' . $uploadFile->file->extension);
         } else {
             print_r($uploadFile->getErrors());
             exit;
         }
     }
     $cats = Categories::find()->where('site_id =' . $this->site->id)->roots()->all();
     $articles = Articles::find()->where('site_id =' . $this->site->id . ' or site_id = 13')->all();
     //$cats = Categories::find()->leaves()->all();
     return $this->render('index', ['cats' => $cats, 'articles' => $articles, 'uploadFile' => $uploadFile]);
 }
    public function detail_ajax($id)
    {
        $rs = Articles::find($id);
        ?>
			<div class="head-post">
				<h2><a href="#"><?php 
        echo $rs->article_title;
        ?>
</a></h2>
				<p>I think your best bet would be to start or join a startup. That's been a reliable way to get rich for hundreds of years.The word "startup" dates from the 1960s, but what happens in one is very similar.</p>
				<div class="meta">
					<span class="author">By <a href="#">Anna Chapman</a></span>
					<span class="time"> Published on May 07, 2004.</span>
				</div>
			</div><!-- /.head-post -->
			<div class="body-post">
				<div class="main-post">
					<div class="entry-post">
						<?php 
        echo $rs->article_content;
        ?>
					</div><!-- /.entry-post -->`
					<div class="tags">
						<h4>In this article:</h4>
						<a href="#">Startups</a>
						<a href="#">Technology</a>
						<a href="#">Millions of dollars</a>
						<a href="#">Paul Graham</a>
					</div>
					<div class="load-comment">
						<a href="#">Load Comments (35)</a>
					</div>
				</div><!-- /.main-post -->
			</div><!-- /.body-post -->
		<?php 
    }
Exemple #8
0
        // dd($data);
    }]);
    Route::get('update', ['as' => 'ORM.update', function () {
        // 更新資料
        $data = \App\Models\Articles::find(1);
        $data->update(['article_title' => 'update test.', 'feature' => true]);
        $data = \App\Models\Articles::where('id', '=', 10);
        $data->update(['article_title' => 'update test=3=.', 'feature' => false]);
        // save方法
        $data = \App\Models\Articles::where('id', '=', 11)->first();
        $data->article_title = 'update test -3-.';
        $data->feature = true;
        $data->save();
    }]);
    Route::get('delete', ['as' => 'ORM.delete', function () {
        $data = \App\Models\Articles::find(2);
        $data->delete();
        \App\Models\Articles::destroy(19, 20);
    }]);
});
Route::get('test', function () {
    // $data = \App\Models\Article::find(5);
    $data1 = \App\Models\Article::all();
    $data2 = \App\Models\Article::where('id', '>', 8);
    $data3 = \App\Models\Article::orderBy('id', 'DESC');
    dd([$data1, $data2, $data3]);
});
/*
Route::get('hello', function(){
	return "Hello World!";
});
Exemple #9
0
 public function search($params)
 {
     $query = Articles::find()->with('articleImg')->andFilterWhere(['or', ['like', 'title', $params], ['like', 'content', $params]])->all();
     return $query;
 }
Exemple #10
0
 public function actionKlavir()
 {
     /*
     
             $query  = new Query();
            // $search_result = $query_search->from('siteSearch')->match($q)->all();  // поиск осуществляется по средством метода match с переданной поисковой фразой.
             $r = $query->from('items')
                  ->match('шкалика')
                  ->all();
     
             var_dump(Items::findOne($r)); exit;
     */
     $article_id = Articles::find()->select('MAX(id)')->scalar();
     if ($article_id) {
         $article = Articles::findOne($article_id);
     } else {
         return $this->redirect(Url::toRoute('articles/index'));
     }
     $artContent = new ArticlesContent();
     if ($artContent->load(Yii::$app->request->post())) {
         $artContent->body = Yii::$app->request->post('ArticlesContent')['body'];
         $artContent->minititle = Yii::$app->request->post('ArticlesContent')['minititle'];
         $artContent->source_id = 434;
         $artContent->articles_id = $article_id;
         if ($this->loadModel($article_id)->site_id == 13) {
             $act = new DiaryActs();
             $act->model_id = 6;
             $act->mark = 1;
             $act->user_id = 8;
             $act->save(false);
         }
         $artContent->save();
         $content = ArticlesContent::find()->where(['articles_id' => $article_id]);
         $dataCont = new ActiveDataProvider(['query' => $content]);
         return $this->render('pages', ['content' => $dataCont, 'model' => $artContent]);
     } else {
         return $this->render('klavir', ['model' => $artContent]);
     }
 }
Exemple #11
0
      ],
            ]);
*/
?>

        </div>
        <div class="col-lg-10">
            <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

            <?php 
echo $form->field($model, 'question')->textInput();
?>
            <?php 
echo $form->field($model, 'article_id')->dropDownList(ArrayHelper::map(\app\models\Articles::find()->all(), 'id', 'title'), ['prompt' => 'Выбрать статью']);
?>
            <?php 
echo $form->field($uploadImg, 'img')->fileInput();
?>
            <?php 
echo $form->field($model, 'answer')->textarea(['rows' => 5, 'cols' => 5, 'id' => 'my-textarea-id']);
?>

            <div class="form-group">
                <?php 
echo Html::submitButton($model->isNewRecord ? 'Создать' : 'Обновить', ['class' => 'btn btn-primary', 'name' => 'create-button']);
?>
            </div>
            <?php 
ActiveForm::end();
 public function softDel()
 {
     $obj = Articles::find(29);
     $obj->delete();
     debug($obj);
     $obj->trashed();
     debug($obj);
     return view('index');
 }
 /**
  * Lists all Articles models.
  * @return mixed
  */
 public function actionIndex()
 {
     $query = Articles::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Articles::PAGE_SIZE]]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
Exemple #14
0
 /**
  * Парсер хабрахабра
  * @param $url
  */
 public function actionHabrParser($url, $title)
 {
     $tag_in = '';
     $tag_out = '';
     $cut = '';
     $source = 329;
     if (strstr($url, 'habrahabr.ru/company')) {
         $tag_in = 'class="company_post"';
         $tag_out = 'class="post__tags"';
     } elseif (strstr($url, 'habrahabr') || strstr($url, 'geektimes')) {
         $tag_in = 'class="post_show"';
         $tag_out = 'class="post__tags"';
     } elseif (strstr($url, 'wikipedia')) {
         $tag_in = 'id="mw-content-text"';
         $tag_out = 'printfooter';
         $source = 394;
     } elseif (strstr($url, 'highload')) {
         $tag_in = 'page_wrapper';
         $tag_out = 'social-likes social-likes_visible';
         $source = 394;
     }
     //echo $tag_in;
     //echo $tag_out;  exit;
     header('Content-Type: text/html; charset=utf-8');
     //$head = file_get_contents(Url::to("@app/commands/header.html"));
     $content = $this->get_page($url);
     $content = $this->cut_content($content, $tag_in, $tag_out);
     $allowedTags = '<a><br><b><h1><h2><h3><h4><i>' . '<img><li><ol><p><strong><table><pre>' . '<tr><td><th><u><ul>';
     $content = strip_tags($content, $allowedTags);
     $content = preg_replace('$\\[.*?\\]$', '', $content);
     $content = str_replace('id="mw-content-text" lang="ru" dir="ltr" class="mw-content-ltr">', '', $content);
     $artContent = new ArticlesContent();
     $artContent->articles_id = (int) Articles::find()->select('MAX(id)')->scalar();
     $artContent->source_id = $source;
     $artContent->body = $content;
     $artContent->minititle = $title;
     $artContent->save(false);
     //var_dump($artContent);
 }