Comments (17)
This change is enough. If you plan upgrade from Yii 1 version you also need update level column values to level - 1.
Class root does not exist
This can't be caused be behavior. Can you show your model dump?
from yii2-nested-sets.
after some testing, I found out that it happens when I then want to go like /controller/view/15.
So actually for all actions that GII has created. At your extension for Yii1 there it was necessary to remove all validations from the rules. Is this necessary for this yii2 too?
from yii2-nested-sets.
At your extension for Yii1 there it was necessary to remove all validations from the rules. Is this necessary for this yii2 too?
Currently yes, you need remove required
validator from this attributes. But seems you give me idea about removing this limitations 👍
from yii2-nested-sets.
Hmmm, after removed the required, it still is not working.
Have you ever tried it on a Gii-generated MVC?
I always get a "Class root does not exist". Even when I just try this:
Node::find()->roots()->all();
from yii2-nested-sets.
Have you ever tried it on a Gii-generated MVC?
Ofcourse, with Gii generated model.
As i said this error
Class root does not exist
Can't be caused by behavior in any case. This error of your model layer. Can you provide your model dump to investigate situation and help?
from yii2-nested-sets.
That is very kind of you :-)
This is my model:
namespace frontend\models;
use Yii;
use frontend\components\NestedQuery;
use creocoder\nestedsets\NestedSetsBehavior;
/**
* This is the model class for table "node".
*
* @property integer $id
* @property integer $map_id
* @property integer $root
* @property integer $lft
* @property integer $rgt
* @property integer $level
* @property integer $link_node_id
*
* @property Map $map
* @property NodeValue[] $nodeValues
*/
class Node extends \yii\db\ActiveRecord {
/**
* @inheritdoc
*/
public static function tableName() {
return 'node';
}
/**
* @inheritdoc
*/
public function rules() {
return [
[['map_id', 'root', 'lft', 'rgt', 'level', 'link_node_id'], 'integer'],
//not needed because of nestedSet
//[['root', 'lft', 'rgt', 'level'], 'required']
];
}
/**
* @inheritdoc
*/
public function attributeLabels() {
return [
'id' => Yii::t('app', 'ID'),
'map_id' => Yii::t('app', 'Map ID'),
'root' => Yii::t('app', 'Root'),
'lft' => Yii::t('app', 'Lft'),
'rgt' => Yii::t('app', 'Rgt'),
'level' => Yii::t('app', 'Level'),
'link_node_id' => Yii::t('app', 'Link Node ID'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getMap() {
return $this->hasOne(Map::className(), ['id' => 'map_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getNodeValues() {
return $this->hasMany(NodeValue::className(), ['node_id' => 'id']);
}
public function behaviors() {
return [
'class' => NestedSetsBehavior::className(),
'treeAttribute' => 'root',
'leftAttribute' => 'lft',
'rightAttribute' => 'rgt',
'depthAttribute' => 'level',
];
}
public function transactions() {
return [
self::SCENARIO_DEFAULT => self::OP_ALL,
];
}
public static function find() {
return new NestedQuery(get_called_class());
}
}
from yii2-nested-sets.
@gb5256 Ok, all fine there. Also i need your frontend\components\NestedQuery
dump. Btw usually this class place is also models
and not components
. Just FYI.
from yii2-nested-sets.
namespace frontend\components;
(Well, I have put it into a components folder as i did it this way in yii1, so just a old habit...)
namespace frontend\components;
use creocoder\nestedsets\NestedSetsQueryBehavior;
class NestedQuery extends \yii\db\ActiveQuery {
public function behaviors() {
return [
NestedSetsQueryBehavior::className(),
];
}
}
from yii2-nested-sets.
@gb5256 Are you sure you get error with description:
Class root does not exist
? It only can be caused if somewhere you have not existent call to class named root()
. But there is nothing like that in your dumps. I suggest to temporary comment relations methods and try to call Node::find()->roots()->all();
again.
from yii2-nested-sets.
@gb5256 I guess something wrong inside Map
or NodeValue
or controller and view. And this something probably caused by find/replace :)
from yii2-nested-sets.
@gb5256 So try to comment relations. Create empty controller and just call Node::find()->roots()->all();
. I bet everything will be fine 👍 If so than next you need to find error inside related models or controller/view which lead to this low level php error like class not exist
.
from yii2-nested-sets.
grrrrr.
I dont get it.
I have an empty controller like this:
namespace frontend\controllers;
use Yii;
use frontend\models\Node;
use frontend\models\_search\NodeSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
class NodeController extends Controller {
public function actionIndex() {
$root = Node::find()->roots()->all();
}
}
as you see I am not even calling a view, just calling the roots()
I have also removed all relations from the model.
Still the same.
Looking at the error output, this is happening:
../vendor/creocoder/yii2-nested-sets/src/NestedSetsQueryBehavior.php – yii\base\Object::__construct()
in line 28 it calls
$model = new $this->owner->modelClass();
This is then handed over to yii which constructs it and throws in the end a
ReflectionException
Class root does not exist
from yii2-nested-sets.
I think we have an error in the docs. See here #56
from yii2-nested-sets.
AHHHHHHHHHHHHHHH.
@Mihai-P : you are perfectly right. Now it works. The documentation is wrong !!!!
from yii2-nested-sets.
@Mihai-P Thanks you! Doc fixed! :) It was really hard to understand what was wrong by looking at dumps provided by @gb5256
from yii2-nested-sets.
Sorry about that, I think everybody has multiple behaviors defined so
nobody saw the missing brackets.
Best regards,
Mihai Petrescu
[email protected]
+61 438 002 393
On Tue, Jan 27, 2015 at 10:53 AM, gb5256 [email protected] wrote:
AHHHHHHHHHHHHHHH.
@Mihai-P https://github.com/Mihai-P : you are perfectly right. Now it
works. The documentation is wrong !!!!—
Reply to this email directly or view it on GitHub
#55 (comment)
.
from yii2-nested-sets.
@creocoder Perhaps you can also add to the docs your comment about upgrading from yii1 to reduce all levels by -1.
Anyway: thanks everybody for getting this running. Highly appreciated.
from yii2-nested-sets.
Related Issues (20)
- How to create hierarchical Html::Menu() with nested sets? HOT 1
- is there a function to get all left node?
- Breadcrumbs? HOT 2
- how to get data with pagination ???
- Allow for a custom root depth value
- Как сортировать деревья?
- Make Root on Insert param
- Behaviour can work with PostgreSQL ? HOT 3
- Can get the Parents, but not the Childrens HOT 1
- Feature Request: Sort tree alphabetically
- On Going or Dead? HOT 5
- Must be 'Menu' class? HOT 6
- Left/right/depth attributes not updated on the record after update
- How to filter in GridView on parent? HOT 9
- Как получить все деревья HOT 2
- Question: is it possible to get a node with parents before like in a breadcrumb? HOT 2
- Перенос узлов дерева мышью HOT 1
- There are no changes in the afterSave method HOT 1
- Как получить категорию по связи hasOne?
- вывод на view дерево HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-nested-sets.