/**
  * Finds the Categories model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Categories the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Categories::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #2
0
 public function getOne($category_id = Null)
 {
     $data = models\Categories::find()->where(['id' => $category_id])->one();
     if ($data === null) {
         return false;
     }
     $catData = $data->attributes;
     $uploadThumbs = $this->uploadThumbs;
     foreach ($uploadThumbs as $thumbType => $sizes) {
         if (empty($catData['image'])) {
             $catData['image_' . $thumbType] = false;
         } else {
             $catData['image_' . $thumbType] = Url::to($this->uploadUrl . '/' . $thumbType . '/' . $catData['image']);
         }
     }
     $countChilds = models\Categories::find()->where(['parent_id' => $data->id])->count();
     if ($countChilds > 0) {
         $catData['sub_categories'] = $this->getAll($parent_id = $data->id);
     }
     $arr[] = $catData;
     return $arr;
 }
Example #3
0
<?php

/*
 * This file is part of the YiiModules.com
 *
 * (c) Yii2 modules open source project are hosted on <http://github.com/yiimodules/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use yiimodules\categories\models\Categories;
use yii\helpers\Html;
use yii\widgets\DetailView;
?>

<div class="clearfix">&nbsp;</div>

<?php 
echo DetailView::widget(['model' => $model, 'attributes' => [['attribute' => 'image', 'value' => Categories::getImage($model->id, 'small', ['class' => 'thumbnail']), 'format' => 'raw'], 'id', ['attribute' => 'parent_id', 'value' => Html::a(Html::getAttributeValue($model, 'parentCategory[name]'), ['/categories', 'id' => $model->parent_id]), 'format' => 'raw', 'visible' => $model->parent_id == 0 ? false : true], 'name', 'slug', 'description', 'meta_title', 'meta_keywords', 'meta_description', ['attribute' => 'is_active', 'value' => $model->is_active == 1 ? "Active" : "Inactive", 'format' => 'raw'], ['attribute' => 'created_at', 'value' => $model->created_at != '' ? date('d M Y h:s') : "(not set)", 'format' => 'raw'], ['attribute' => 'updated_at', 'value' => $model->updated_at != '' ? date('d M Y h:s a') : "(not set)", 'format' => 'raw']]]);
Example #4
0
						<span class="navbar-brand">
							<?php 
if ($parentCategory) {
    ?>
							<?php 
    echo Categories::printEditPath(Html::getAttributeValue($parentCategory, 'id'));
    ?>
 - New Subcategory
							<?php 
} else {
    ?>
								<?php 
    if ($model->id != "") {
        ?>
								<?php 
        echo Categories::printEditPath(Html::getAttributeValue($model, 'id'));
        ?>
 - Update category information
								<?php 
    } else {
        ?>
								New Root Category
								<?php 
    }
    ?>
							<?php 
}
?>
						</span>
					</div>
					<div class="pull-right" style="margin-top:8px">
<?php

/*
 * This file is part of the YiiModules.com
 *
 * (c) Yii2 modules open source project are hosted on <http://github.com/yiimodules/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use yiimodules\categories\models\Categories;
?>

<div class="clearfix">&nbsp;</div>

<?php 
echo $form->field($model, 'image')->fileInput();
?>

<?php 
if ($model->id != "") {
    echo Categories::getImage($model->id, 'medium', ['class' => 'thumbnail']);
}