public function actionIndex()
 {
     $mainSlider = Slider::find()->all();
     $gallery = Gallery::find()->all();
     $blog = Blog::find()->limit(2)->all();
     return $this->render('index', ['mainSlider' => $mainSlider, 'gallery' => $gallery, 'blog' => $blog]);
 }
예제 #2
0
 public function update($post, Request $request)
 {
     $post = Blog::find($post);
     $post->fill($request->all());
     $post->save();
     flash()->success('Ви успішно змінили статтю!');
     return redirect(route('blog.page', ['id' => $post->id]));
 }
예제 #3
0
 /**
  * AJAX
  * Добавляет site_update
  * Делает рассылку
  *
  * @param integer $id - идентификатор статьи
  *
  * @return string
  */
 public function actionSubscribe($id)
 {
     $item = Blog::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();
 }
예제 #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Blog::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, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'topic', $this->topic])->andFilterWhere(['like', 'detail', $this->detail])->andFilterWhere(['like', 'tag', $this->tag]);
     return $dataProvider;
 }
예제 #5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Blog::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => []]]);
     $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, 'department_id' => $this->department_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
예제 #6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Blog::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, 'user_id' => $this->user_id, 'create_date' => $this->create_date]);
     $query->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'artictle', $this->artictle]);
     return $dataProvider;
 }
예제 #7
0
 /**
  * Delete a blog.
  *
  * @param string $id
  *
  * @return Redirect
  */
 public function destroy($id)
 {
     // delete
     $blog = Blog::find($id);
     $blog->delete();
     // redirect
     $request->session()->flash('success', trans('blog.blog') . ' ' . trans('crud.deleted'));
     return redirect('admin/blog');
 }
예제 #8
0
 /**
  * Update the specified resource in storage.
  *
  * @param \Illuminate\Http\Request $request
  * @param int                      $id
  *
  * @return \Illuminate\Http\Response
  */
 public function update(BlogsRequest $request, $society, $id)
 {
     $blog = Blog::find($id);
     $blog->fill($request->except('societies', 'subjects'));
     $blog->societies = implode(',', $request->input('societies'));
     if ($request->input('subjects') != "") {
         $newsubjs = array_map('intval', $request->input('subjects'));
         $blog->subject()->sync($newsubjs);
     } else {
         $blog->subject()->detach();
     }
     if ($request->file('blogimage')) {
         $fileName = "blogimage_" . $blog->id . "." . $request->file('blogimage')->getClientOriginalExtension();
         $request->file('blogimage')->move(base_path() . '/storage/app/images/', $fileName);
         $blog->blogimage = '/storage/app/images/' . $fileName;
     }
     $blog->save();
     return redirect(url('/') . '/' . $society . '/blogs')->with('okmessage', 'Data updated');
 }
예제 #9
0
 public function actionBlog_item($year, $month, $day, $id)
 {
     $date = $year . $month . $day;
     $pattern = '#^[a-z\\d_-]+$#';
     if (!preg_match($pattern, $id)) {
         throw new BadRequestHttpException('Имеются запрещенные символы');
     }
     $item = Blog::find(['date' => $date, 'id_string' => $id]);
     if (is_null($item)) {
         throw new HttpException(404, 'Нет такой статьи');
     }
     $item->incViewCounter();
     $nearList = Blog::query()->select('id,header,id_string,image,view_counter,description,date_insert,date')->orderBy(['date_insert' => SORT_DESC])->andWhere(['not in', 'id', $item->getId()])->limit(3)->all();
     return $this->render(['item' => $item, 'nearList' => $nearList]);
 }
예제 #10
0
 /**
  * Lists all Blog models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Blog::find()->where('id_user='******' or not personal')]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
예제 #11
0
파일: Blog.php 프로젝트: Crocodile26/php-1
 public static function baseInfo($id)
 {
     $id = intval($id);
     return Blog::find()->where(['id' => $id])->select(self::$select_fields_list)->asArray()->one();
 }
예제 #12
0
 public function actionResult()
 {
     $modelBlog = Blog::find()->all();
     return $this->render('/parser/result', ['modelBlog' => $modelBlog]);
 }
예제 #13
0
$post = \Yii::$app->request->post();
if (!empty($post)) {
    $blog = new Blog();
    $blog->name = $post['name_article'];
    $blog->body = $post['body_article'];
    $blog->date_create = date("y.m.d");
    $blog->author = '1';
    $blog->insert();
    Yii::$app->response->redirect(['main/blog']);
}
?>
<div class="Blog">
<h1>Блог</h1>
<div class="artcls">
<?php 
$articles = Blog::find()->orderBy('id')->all();
if (!empty($articles)) {
    echo "<ul>";
    foreach ($articles as $article) {
        echo "<li><p>" . $article['name'] . "</p><p>" . $article['body'] . "</p></li>";
    }
    echo "</ul>";
} else {
    echo "<p>Нет записей</p>";
}
?>
</div>
<div class="artclCrt">
<?php 
ActiveForm::begin(['method' => 'post', 'action' => ['']]);
?>