/** * Показывает контент * @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]); }
public function actionTransformFile() { $docObj = new DocxConverter(Url::to("web/uploads/file.docx")); $docText = $docObj->convertToText(); $result = preg_split("/(\\.poe\\s|\\.his\\s|\\.che\\s|\\.pc\\s|\\.pc-his\\s|\\.foo\\s|\\.pic\\s|\\.se\\s|\\.enc\\s|\\.mat\\s|\\.myt-gb\\s|\\.myt-gb\\s)/", $docText, -1, PREG_SPLIT_DELIM_CAPTURE); $model = new Articles(); $model->text = $result[0]; $model->title = ''; $model->alias = ''; $model->site_id = 7; $model->cat_id = 57; $model->tags = ''; $model->source_id = 2; if ($model->save(false)) { echo "Head copied"; } }
protected function findModel($id) { if (($model = Articles::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Run the database seeds. * 新增假資料 * @return void */ public function run() { Articles::truncate(); $time = Carbon::now('Asia/Taipei')->subweeks(3); foreach (range(1, 20) as $value) { $time->addDay(); Articles::create(['article_title' => '文章測試' . $value, 'article_content' => '這是一篇測試文章,第' . $value . '篇。', 'feature' => rand(0, 1), 'page_view' => rand(0, 200), 'created_at' => $time, 'updated_at' => $time]); } }
public function jobView(Request $request, $id) { //$id = 5555; $article = Articles::findOrFail($id); if (empty($article)) { debug('no one'); } debug($article); return view('index'); }
/** * 预载入 * 是用来减少 N + 1 查询问题 * * 这里的 user 为Articles 模型里面的 user() 方法 */ public function preLoad() { //直接读取所有的字段 $rows = Articles::with('user')->get()->toArray(); //有选中的读取字段,但是字段中必须包含关联的键 $rows = Articles::with(['user' => function ($query) { return $query->select('username', 'id'); }])->select('title', 'user_id')->get()->toArray(); debug($rows); return view('index'); }
/** * 取得 模型 所有的 字段 * * 并且对 每个字段 进行 赋值 * * @param $id * @param array $fields * @return array */ protected function fieldsFromModel($id, array $fields) { $article = Articles::findOrFail($id)->toArray(); //debug($article); $fieldNames = array_keys($article); //debug($fieldNames); $fields = ['id' => $id]; foreach ($fieldNames as $field) { $fields[$field] = $article[$field]; } return $fields; }
/** * Показываем контент * @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]); }
/** * 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]); }
public function search($params) { $query = Articles::find()->with('articleImg')->andFilterWhere(['or', ['like', 'title', $params], ['like', 'content', $params]])->all(); return $query; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(Request $request) { Articles::destroy($request->aID); return "success"; }
/** * Run the database seeds. * * @return void */ public function run() { Eloquent::unguard(); Articles::create(['title' => 'Test', 'content' => 'This is just a sample article', 'slug' => 'this-is-just-a-sample-article', 'month' => Carbon::now()->month, 'year' => Carbon::now()->year, 'author' => 1, 'category_id' => 1]); }
public function getArticle() { return $this->hasOne(Articles::className(), ['id' => 'article_id']); }
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]); } }
public function actionArticlechange() { $arr['Art_Num'] = 350; $article = new Articles(); $article->updateArticles(2, $arr); }
public function actionOne() { $this->view->values = Articles::findOne((int) $_GET['id']); $this->view->display('one'); }
/** * Парсер хабрахабра * @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); }
/** * 内联查询 * */ public function innerWhere() { $condition = ['TCC', 'tmm', 'tangmm']; $obj = new Articles(); /** * 在循环 内联 查询时,有初始查询条件,与没有初始查询条件的 巨大差异 * 无初始查询条件:最后的sql 语句 就是 循环里面的 每次sql 语句 * 有初始条件: 最后的sql 语句 是,循环里面的 所有条件的 每次拼接 */ //$obj = $obj->where('status',1); foreach ($condition as $value) { $total = $obj->where(function ($query) use($value) { return $query->where('id', $value)->orWhere('content', $value); })->count(); } }
/** * Display the specified category. * * @param int $id * @return Response */ public function show($category, $article) { $cat = Category::where('slug', $category)->first(); $article = Articles::where('category', $cat->id)->first(); return View::make('articlesshow', ['articles' => $article::all()]); }
public function vnexpress_set_important_news() { //============ ============ // Tạo column mới: article_mode // $html = file_get_contents("http://vnexpress.net"); $dom = str_get_html($html); $link_important = $dom->find(".line_col_midnews_top .content_scoller li a"); foreach ($link_important as $key => $value) { if (Articles::where("article_link", $value->attr["href"])->update(["article_mode" => 1])) { echo Articles::where("article_link", $value->attr["href"])->first()->article_title . PHP_EOL; // echo $value->attr["href"].PHP_EOL; } } // //============ ============ }
Route::post('/article/store', 'article@store'); Route::post('/article/destroy', 'article@destroy'); Route::get('/navigator', 'navigator@index'); Route::get('/navigator/create', 'navigator@create'); Route::post('/navigator/store', 'navigator@store'); Route::post('/navigator/destroy', 'navigator@destroy'); }); }); Route::bind('searchTag', function ($tag) { return Articles::where('aTag', 'like', '%' . $tag . '%')->leftJoin('categories', 'categories.cID', '=', 'articles.cID')->leftJoin('users', 'users.uID', '=', 'articles.uID'); }); Route::bind('searchCategory', function ($category) { return Articles::where('cName', $category)->leftJoin('categories', 'categories.cID', '=', 'articles.cID')->leftJoin('users', 'users.uID', '=', 'articles.uID'); }); Route::bind('post', function ($id) { return Articles::where('aIsActive', 1)->where('aID', $id)->leftJoin('categories', 'categories.cID', '=', 'articles.cID')->leftJoin('users', 'users.uID', '=', 'articles.uID')->first(); }); Route::group(['namespace' => 'user'], function () { Route::get('/', 'home@index'); Route::get('/show-post/{post}', 'home@post'); Route::get('/contact', 'home@contact'); Route::get('/search/', function () { return "this function will be implemented soon!"; }); Route::get('/search/tag/{searchTag}', 'home@searchTag'); Route::get('/search/category/{searchCategory}', 'home@searchCategory'); Route::get('/about-me', function () { return view('user.about-me'); }); Route::any('/crawler', 'functionally@crawler'); Route::get('/sendMessage', 'functionally@message');
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!"; }); Route::get('post/{id}', function($id) {
/** * 获取article物品 */ public function actionGetarticledata() { $article = new Articles(); $result = $article->showarticledata(1, 6); echo $result; }
public function actionDelete() { $article = Articles::findOne((int) $_GET['id']); $article->delete(); header('Location: http://test/'); }
], ]); */ ?> </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 getArticles() { return $this->hasMany(Articles::className(), ['id' => 'article_id'])->viaTable('category_article', ['category_id' => 'id']); }
public function delete($slug) { if (Input::has('selected_article')) { return Redirect::to('admin/articles/' . Input::get('selected_article') . '/delete'); } else { if (Input::has('confirmed_delete')) { try { $article = Articles::where($slug, $slug)->get(); Articles::where('slug', $slug)->get()->delete(); return View::make('admin.articles.delete', ['status' => 'successful', 'article' => $article, 'articles' => Articles::all(), 'id' => $article->id]); } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) { return View::make('admin.articles.delete', ['status' => 'unsuccessful', 'article' => $article, 'id' => $id]); } } else { $article = Articles::where('slug', $slug); return View::make('admin.articles.delete', ['status' => 'confirm', 'article' => $article, 'articles' => Articles::all(), 'id' => $id]); } } }
public function article_imgs_show_all_img_article() { $rs = Articles::limit(40)->get(); foreach ($rs as $key => $value) { $array = json_decode($value->article_imgs, true); foreach ($array as $key2 => $value2) { } } //============ ============ // $json = json_encode($return); // Lưu file ngoài root // file_put_contents(time().".json", $json); dd($return); }