Exclude some Category in tree


(dzoshua) #1

Dear all,
I have problem with category tree, because when I open Category, on left side I have dropdown list and I have same name of primary category. I try to hide or exclude primary category, just show other category in this dropdown list.
This is part of code in my controller:

public function actionKancelarijskiMaterijal($category_id = 4)
{
    $kategorije = Catalog::tree();
    $podkategorije = Category::find()->where(['tree'=>4])->all();
    $request = Yii::$app->request;
    $filters = $request->post();
    //echo '<pre>';print_r($filters);print_r($_POST);exit;
    //if ($filters) {
        $fieldFilter = [];
        foreach ($filters as $key => $value) {
            if ($key == '_csrf')
                continue;

            $filterItem = [];
            $filterOptions = $filters[$key];
            $filterTitle = $key;
            //echo $filterTitle.'----';
            //print_r($filterOptions);
            $options = [];
            //echo '<pre>';print_r($filterOptions);exit;
            //if (count($filterOptions) > 0) {
                foreach($filterOptions as $key1 => $value1){
                    $options[] = $value1;//$filterOptions[$key1];
                }
            //}
            $filterItemOptions[] = $options;
            //$filterItem[] = $filterItemOptions;
            $fieldFilter[$filterTitle] = $options;
        }
        //echo '<pre>';print_r($fieldFilter);

    $items = Catalog::items(['where' => ['category_id' => $category_id], 'filters' => $fieldFilter]);

    $kategorija = Catalog::cat( $category_id );
    $goods = Shopcart::goods();

    return $this->render('kancelarijski_materijal',
        [
            'kategorije'=>$kategorije,
            'podkategorije'=>$podkategorije,
            'goods'=>$goods,
            'kategorija'=>$kategorija,
            'items'=>$items
        ]);
}

Can anyone help for this? Number id 4 is id of my primary category and I want this id exclude in dropdown list or hide.


(demonking) #2

You could exclude them from your Query
For Example:

andWhere(['!=', 'category_id', '4'])

(dzoshua) #3

Where I place that piece of code?
Is it between: Category::find()->>where([‘tree’=>4])->>all() and before ; ?


(demonking) #4

When you can provide more information?
Maybe a Database Scheme .


(dzoshua) #5

I used EasyiiCMS and in backend I have tree where Kancelarijski Materijal is primary and other all is subcategory.