/**
  * Updates an existing Category 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);
     $parent_category = [];
     $get_categorys = [];
     $get_category = Category::getCateory($model->parent_category);
     if (!empty($get_category)) {
         // cek jika parent nya adalah level pertama sperti kategori produk , kategori berita
         $get_categorys = Category::getCategories($get_category->parent_category);
         if (!empty($get_categorys)) {
             $model->sub_category = $model->parent_category;
         }
         if (!empty($get_category) && ($get_category->parent_category !== 0 && $get_category->parent_category !== '')) {
             $parent_category = Category::getParentCategorys($get_category->id);
             $model->parent_category = $get_category->parent_category;
         } else {
             $parent_category = Category::getParentCategorys($model->id);
             //                echo '<pre>';print_r($parent_category);die;
         }
     } else {
         $parent_category = Category::getParentCategorys($model->parent_category);
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'parent_category' => $parent_category, 'sub_categorys' => $get_categorys]);
     }
 }
Example #2
0
use backend\assets\CategoryAsset;
use backend\models\Category;
/* @var $this yii\web\View */
/* @var $model backend\models\Category */
CategoryAsset::register($this);
$this->title = $model->nama;
$this->params['breadcrumbs'][] = ['label' => 'Categories', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="category-view">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
        <?php 
echo Html::a('Delete', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]);
?>
    </p>

    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'nama', 'deskripsi:ntext', ['label' => 'Parent Category', 'value' => $model->parent_category != 0 ? Category::getCateory($model->parent_category)->nama : 'Not Set'], ['label' => 'Status', 'value' => Category::getStatus($model->status)], 'date_create', 'date_update']]);
?>

</div>
Example #3
0
$this->title = 'Kategori';
$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, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'id', 'format' => 'raw', 'value' => function ($model) {
    return "#" . $model->id;
}], 'nama', 'deskripsi:ntext', ['attribute' => 'parent_category', 'format' => 'raw', 'value' => function ($model) {
    return $model->parent_category != 0 ? Category::getCateory($model->parent_category)->nama : '-';
}], ['attribute' => 'status', 'format' => 'raw', 'value' => function ($model) {
    return Category::getStatus($model->status);
}], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Example #4
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->isNewRecord) {
         } else {
         }
         //            $this->_oldTag = $this->tag;
         $this->user_by = \Yii::$app->user->identity->nama_depan;
         $this->schedule_date = date('Y-m-d H:i:s', strtotime(str_replace("-", "", $this->schedule_date)));
         isset($this->author) ? $this->author_name = User::getUser($this->author)->nama_depan : ($this->author_name = NUll);
         isset($this->categori_id) ? $this->categori_name = Category::getCateory($this->categori_id)->nama : ($this->categori_name = NUll);
         return true;
     } else {
         return false;
     }
 }