PHP code example of kr0lik / yii2-tree-manager
1. Go to this page and download the library: Download kr0lik/yii2-tree-manager library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
kr0lik / yii2-tree-manager example snippets
use app \path \to \YourActiveRecord ;
use kr0lik \tree \TreeManagerAction ;
use yii \web \Controller ;
use yii \widgets \ActiveForm ;
class YourController extends Controller
{
public function actions ()
{
return [
'tree' => [
'class' => TreeManagerAction::class,
'treeModelClass' => YourActiveRecord::class,
'formNameField' => 'title' ,
'formFields' => [
'description' ,
function (ActiveForm $form, YourActiveRecord $model) {
return $form->field($model, 'body' )->textarea();
},
],
'formLinks' => [
function (YourActiveRecord $model) {
return Html::a('View' , ['/url/to/view' , 'id' => $model->id], ['class' => 'btn btn-sm btn-info' ]);
},
]
]
];
}
}
use kr0lik \tree \TreeManagerWidget ;
use yii \web \Controller ;
use kr0lik \tree \TreeAction ;
use app \path \to \YourActiveRecord ;
class YourController extends Controller
{
public function actions ()
{
return [
'tree' => [
'class' => TreeAction::class,
'treeModelClass' => YourActiveRecord::class,
]
];
}
}
use kr0lik \tree \TreeInput ;
use yii \web \Controller ;
use kr0lik \tree \TreeRelationAction ;
use app \path \to \YourTreeActiveRecord ;
use app \path \to \YourRelationActiveRecord ;
class YourController extends Controller
{
public function actions ()
{
return [
'tree' => [
'class' => TreeRelationAction::class,
'treeModelClass' => YourTreeActiveRecord::class,
'relationModelClass' => YourRelationActiveRecord::class,
]
];
}
}
use kr0lik \tree \TreeInput ;
return [
'components' => [
'i18n' => [
'translations' => [
'kr0lik.tree' => [
'class' => 'yii\i18n\PhpMessageSource' ,
'basePath' => '@kr0lik/tree/messages' ,
],
],
],
],
];
'params' => [
'bsVersion' => 4 ,
],