i have install tree view extension from kartik. I follow the documentations, but i'm not able to create the root node. My model extends active record and this is the code:
<?php
namespace common\models;
use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
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'],
],
],
];
}
/**
* {@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']);
}
My controller is :
public function actionTree()
{
return $this->render('tree', []);
}
When i visit the view all works but if i try to create a root i get this error in my console browser
{"out":"Callingunknown method: common\models\Pages::isLeaf()","status":"error"}
UPDATE I isolated the part of the code that gives me the error and refers to this inside the model:
public function behaviors( ) {
return [
[
'class' => TimestampBehavior::class,
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at','updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
],
],
];
}