kartik-v / yii2-tree-manager

An advanced tree management module using nested sets for Yii 2.
http://demos.krajee.com/tree-manager
Other
150 stars 107 forks source link

How to add a new parameter in tree view widget? #237

Closed rahmanjalayer closed 5 years ago

rahmanjalayer commented 5 years ago

I'm using tree view in my project. I want to set a new param in treeView widget like follow:

 echo \kartik\tree\TreeView::widget([
        'query' => \backend\models\Regulation::find()->addOrderBy('root, lft')->andWhere(['selectedForParvandeh' => $parvandehVersionID])->andWhere(['>', 'lvl', '0']),
        'rootOptions' => ['label' => '<span class="text-primary">p1</span>'],
        'topRootAsHeading' => true, // this will override the headingOptions
        'fontAwesome' => true,
        'isAdmin' => true,
        'iconEditSettings' => [
            'show' => 'none',
        ],
        'softDelete' => false,
        'cacheSettings' => ['enableCache' => true],
        'calledFrom' => true,
    ]);

as you can see above, "calledFrom" param is added. I want to access to this in nodeController. for this reason, I've added follow code in TreeView class: public $calledFrom = false; then I edited at renderDetail function:

$manageData = TreeSecurity::parseManageData([
            'formOptions' => $this->nodeFormOptions,
            'modelClass' => $modelClass,
            'formAction' => $this->nodeActions[Module::NODE_SAVE],
            'currUrl' => $url,
            'isAdmin' => $this->isAdmin,
            'gg' => $this->gg,
            'iconsList' => $this->_nodeIconsList,
            'softDelete' => $this->softDelete,
            'allowNewRoots' => $this->allowNewRoots,
            'showFormButtons' => $this->showFormButtons,
            'showIDAttribute' => $this->showIDAttribute,
            'showNameAttribute' => $this->showNameAttribute,
            'nodeView' => $this->nodeView,
            'nodeAddlViews' => $this->nodeAddlViews,
            'nodeViewButtonLabels' => $this->nodeViewButtonLabels,
            'nodeSelected' => $this->_nodeSelected,
            'breadcrumbs' => $this->breadcrumbs,
            'noNodesMessage' => Html::tag('div', $this->emptyNodeMsg, $this->emptyNodeMsgOptions),
            'nodeTitle' => $this->nodeTitle,
            'nodeTitlePlural' => $this->nodeTitlePlural,
            'defaultBtnCss' => $this->getDefaultBtnCss(),
            'calledFrom' => $this->calledFrom,

        ]);

to make long story short, I've added "calledFrom" variable every where which "isAdmin" is used. but I can't access it within nodeController/actionManage. I know my description is complicated. but I would be thankful, if you could help me to define a new param and use it in nodeController/actionManage.

rahmanjalayer commented 5 years ago

is there no one can help me??!!!!! :(

kartik-v commented 5 years ago

You can just add additional custom attributes to your TreeModel as described here with appropriate validation rules.

Then you can just include these additional attributes as inputs in your tree node form that will be automatically parsed by the NodeController.

To add additional editable inputs for these custom inputs, just set them your custom view and configure in nodeAdditionalViews

fasi1208 commented 4 years ago

I don't want to add the additional parameters as inputs in my tree. I want to make work them in background.