コード例 #1
0
 /**
  * Creates a new Blog model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Blog();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #2
0
 /**
  * Save a blog.
  *
  * @return Redirect
  */
 public function store(Request $request)
 {
     // store
     $lang = $request->session()->get('language');
     $blog = new Blog();
     $blog->shop_id = $request->shop_id;
     $blog->slug = $request->slug;
     $data = $request->except(['shop_id', 'slug', '_token', '_method']);
     $blog->{$lang} = $data;
     if ($lang == config('app.locale')) {
         $blog->default = $data;
     }
     $blog->save();
     // redirect
     $request->session()->flash('success', trans('blog.blog') . ' ' . trans('crud.created'));
     return redirect('admin/blog/' . $blog->id . '/edit');
 }
コード例 #3
0
ファイル: ParserController.php プロジェクト: kotmonstr/parser
 public function actionSimple()
 {
     ini_set('max_execution_time', 0);
     ini_set('memory_limit', '128M');
     ini_set('default_charset', 'UTF-8');
     //header('Content-Type: text/html; charset=UTF-8');
     $arrResult = [];
     $arrResult2 = [];
     $html = new simple_html_dom();
     $html->load_file('http://politrussia.com/news/');
     // Find all links
     foreach ($html->find('a.overlink') as $element) {
         //echo $element->href. '<br>';
         $arrResult[] = $element->href;
     }
     //vd($arrResult);
     $i = 0;
     foreach ($arrResult as $key => $link) {
         $html->load_file('http://politrussia.com' . $link);
         $i++;
         $content = $html->find('div[class="news_text"]', 0)->plaintext;
         $title = $html->find('h1[itemprop="name"]', 0)->plaintext;
         foreach ($html->find('img[itemprop="contentUrl"]') as $element) {
             $img2 = 'http://politrussia.com' . $element->src;
         }
         $content2 = mb_convert_encoding($content, "UTF-8", "Windows-1251");
         $title2 = mb_convert_encoding($title, "UTF-8", "Windows-1251");
         $arrResult2[$key]['title'] = $title2;
         $arrResult2[$key]['content'] = $content2;
         $arrResult2[$key]['img'] = $img2;
     }
     foreach ($arrResult2 as $key => $row) {
         $modelBlog = new Blog();
         $modelBlog->title = $row['title'];
         $modelBlog->content = $row['content'];
         $modelBlog->created_at = time();
         $modelBlog->updated_at = time();
         $modelBlog->author = Yii::$app->user->id;
         $modelBlog->image = $row['img'];
         $dublicate = Blog::getDublicateByTitle($row['title']);
         if (!$dublicate) {
             $modelBlog->save();
         }
     }
     return $this->render('/site/index');
 }