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');
/* Start to develop here. Best regards https://php-download.com/ */
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,
]
];
}
}