0

HI, i have install kartik tree manager and i follow the guide. 

but when i try to create a root note I get this error in my browser console.

<![CDATA[YII-BLOCK-HEAD]]><![CDATA[YII-BLOCK-BODY-BEGIN]]>{“out”:”Calling unknown method: common\\models\\Pages::isLeaf()”,”status”:”error”}

This is my model

<?php
 namespace common\models;
 use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
 /**
 * This is the model class for table "pages".
 *
 * @property int $id
 * @property string $pages_name Indica il nome della pagina
 * @property string $pages_tag Indica il tipo di pagina ovvero il modello di riferimento
   * @property int $pages_visibility Indica se la pagina è visibile oppure no
 * @property string|null $pages_meta_description
 * @property string|null $pages_meta_keywords
 * @property string|null $pages_meta_title
 * @property int|null $created_at
 * @property int|null $updated_at
 */
class Pages extends ActiveRecord
{
     use \kartik\tree\models\TreeTrait;
         /**
     * @var string the classname for the TreeQuery that implements the NestedSetQueryBehavior.
     * If not set this will default to `kartik	ree\models\TreeQuery`.
     */
    public static $treeQueryClass; // change if you need to set your own TreeQuery
      /**
     * @var bool whether to HTML encode the tree node names. Defaults to `true`.
     */
    public $encodeNodeNames = true;
      /**
     * @var bool whether to HTML purify the tree node icon content before saving.
     * Defaults to `true`.
     */
    public $purifyNodeIcons = true;
      /**
     * @var array activation errors for the node
     */
    public $nodeActivationErrors = [];
      /**
     * @var array node removal errors
     */
    public $nodeRemovalErrors = [];
      /**
     * @var bool attribute to cache the `active` state before a model update. Defaults to `true`.
     */
    public $activeOrig = true;
          /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'pages';
    }
     public function behaviors( ) {
     return [
            [
                'class' => TimestampBehavior::class,
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at','updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],    
            //Sortable --> da installare
         /*[
             'class' => 'sjaakp\sortable\Sortable',
                'orderAttribute' => 'pages_ord',
         ],*/
     ];
 }
     /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['pages_name', 'pages_tag'], 'required'],
            [['pages_visibility', 'created_at', 'updated_at'], 'integer'],
            [['pages_meta_description', 'pages_meta_keywords'], 'string'],
            [['pages_name', 'pages_tag','pages_meta_title'], 'string', 'max' => 255],
        ];
    }
     /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('backend', 'ID'),
            'pages_name' => Yii::t('backend', 'Pages Name'),
            'pages_tag' => Yii::t('backend', 'Pages Tag'),
            'pages_visibility' => Yii::t('backend', 'Pages Visibility'),
            'pages_meta_description' => Yii::t('backend', 'Pages Meta Description'),
            'pages_meta_keywords' => Yii::t('backend', 'Pages Meta Keywords'),
            'pages_meta_title' => Yii::t('backend', 'Pages Meta Title'),
            'created_at' => Yii::t('backend', 'Created At'),
            'updated_at' => Yii::t('backend', 'Updated At'),
        ];
    }
         /**
     *  Relation with junction table pagesxblock many to many with Block table
     */
    public function getBlocks() {
        return $this->hasMany(Block::className(), ['id' => 'id_block'])
        ->viaTable('pagesxblock', ['id_pages' => 'id']);
    }
}

and this is my View

use kartik\tree\TreeView;
use common\models\Pages;
     echo TreeView::widget([
    // single query fetch to render the tree
    // use the Product model you have in the previous step
    'query' => Pages::find()->addOrderBy('root, lft'), 
    'headingOptions' => ['label' => 'Categories'],
    'fontAwesome' => false,     // optional
    'isAdmin' => false,         // optional (toggle to enable admin mode)
    'displayValue' => 1,        // initial display value
    'softDelete' => true,       // defaults to true
    'cacheSettings' => [        
        'enableCache' => true   // defaults to true
    ]
]);

I don't understand where I'm going wrong
Can someone point me to the right direction?

UPDATE I isolated the part of the code that gives me the error and refers to this inside the model:

<code data-highlighted="yes"></code>
public function behaviors( ) { return [ [ 'class' => TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at','updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'], ], ], ]; }
<code data-highlighted="yes"> </code>
yii2-tree-manager Error when using TreeTrait
Federico Edited question January 30, 2025