/** * @inheritdoc */ public function attributeLabels() { return ['id' => Module::t('general', 'ID'), 'title' => Module::t('general', 'Title'), 'alias' => Module::t('general', 'Alias'), 'desciption' => Module::t('general', 'Desciption'), 'content' => Module::t('general', 'Content'), 'category_id' => Module::t('general', 'Category'), 'image' => Module::t('general', 'Image'), 'meta_title' => Module::t('general', 'Meta Title'), 'meta_desciption' => Module::t('general', 'Meta Desciption'), 'created_by' => Module::t('general', 'Created By'), 'created_date' => Module::t('general', 'Created Date'), 'publish_date' => Module::t('general', 'Publish Date'), 'updated_date' => Module::t('general', 'Updated Date'), 'views' => Module::t('general', 'Views'), 'active' => Module::t('general', 'Active')]; }
echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Post', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php foreach ($search as $hit) { echo $hit->id; echo $hit->title; echo $query->highlightMatches($hit->contents, 'UTF-8'); echo '<br/>'; //secho $hit->author; } ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'title', 'category.title:raw:' . Module::t('general', 'Category'), ['attribute' => 'created_date', 'format' => ['date', 'php:h:i:sA d-m-Y'], 'label' => Module::t('general', 'Created Date')], 'views:raw:' . Module::t('general', 'Views'), 'active:boolean:' . Module::t('general', 'Active'), ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete} {link}', 'buttons' => ['link' => function ($url, $model, $key) { return Html::a('<span class="glyphicon glyphicon-link"></span>', Yii::$app->urlManager->createAbsoluteUrl(['post/front/default/view', 'id' => $model->id, 'alias' => $model->alias])); }]]]]); ?> </div>
/** * Deletes an existing Category model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $currentNode = $this->findModel($id); if (!$currentNode) { throw new NotFoundHttpException(Module::t('general', 'The category not found.')); } $node = Category::find()->select('id')->where(['and', ['>=', 'left', $currentNode->left], ['<=', 'right', $currentNode->right]])->asArray()->all(); try { $currentNode->deleteNode(); // if($delcategory) { Post::deleteAll(['IN', 'category_id', ArrayHelper::getColumn($node, 'id')]); \Yii::$app->session->setFlash('success', Module::t('general', 'Delete category successfull')); // } } catch (Exception $e) { \Yii::$app->session->setFlash('error', $e->getMessage()); } return $this->redirect(['index']); }
<?php use yii\helpers\Html; use yii\grid\GridView; use app\modules\post\Module; /* @var $this yii\web\View */ /* @var $searchModel app\modules\post\models\CategorySearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Module::t('general', 'Post Category'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="category-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Category', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'title', 'label' => 'Tiêu đề', 'value' => function ($model) { return str_repeat('- - ', $model->level) . $model->title; }], ['attribute' => 'id', 'format' => 'raw', 'label' => 'Sắp xếp', 'value' => function ($model) { $str = Html::a('<span class="sortbutton glyphicon glyphicon-triangle-bottom" aria-hidden="true" data-id="' . $model->id . '" data-type="right"></span>', 'javascript:void(0)', ['title' => 'Down']); $str .= Html::a('<span class="sortbutton glyphicon glyphicon-triangle-top" aria-hidden="true" data-id="' . $model->id . '" data-type="left"></span>', 'javascript:void(0)', ['title' => 'Up']);
<?php use yii\helpers\Html; use app\modules\post\Module; /* @var $this yii\web\View */ /* @var $model app\modules\post\models\Post */ $this->title = 'Create Post'; $this->params['breadcrumbs'][] = ['label' => 'Posts', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; $this->params['menuAction'] = [['label' => Module::t('general', 'List Post'), 'url' => ['index'], 'options' => ['class' => 'aui-button']]]; ?> <div class="post-create"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php echo $this->render('_form', ['model' => $model]); ?> </div>
/** * Updates an existing Post model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if (Yii::$app->request->isPost) { $postData = Yii::$app->request->post()[StringHelper::basename($model->className())]; var_dump(Yii::$app->request->post()); $datep = date_parse_from_format('d/m/Y h:i:sA', $postData['publish_date']); $postData['publish_date'] = (int) mktime($datep['hour'], $datep['minute'], $datep['second'], $datep['month'], $datep['day'], $datep['year']); $model->title = $postData['title']; $model->alias = $postData['alias']; $model->desciption = $postData['desciption']; $model->content = $postData['content']; $model->category_id = $postData['category_id']; $model->image = $postData['image']; $model->meta_title = $postData['meta_title']; $model->meta_desciption = $postData['meta_desciption']; $model->publish_date = $postData['publish_date']; $model->active = $postData['active']; if (empty($model->alias)) { $model->alias = Inflector::slug($model->title); } if ($model->save()) { \Yii::$app->session->setFlash('success', Module::t('general', 'Update post successfull')); return $this->redirect(['index']); } else { var_dump($model); var_dump($model->getErrors()); } } else { return $this->render('update', ['model' => $model]); } }