creocoder / yii2-nested-sets

The nested sets behavior for the Yii framework.
Other
446 stars 129 forks source link

Class 'creocoder\nestedsets\NestedSetsBehavior' not found #98

Open yougeen opened 8 years ago

yougeen commented 8 years ago

Hi,

I followed the read me and used composer for the installation and I cannot install this extension properly.

When I call

$countries = new Menu(['name' => 'Countries']);
$countries->makeRoot();

I receive Class 'creocoder\nestedsets\NestedSetsBehavior' not found

Can someone help me please? Thanks!

yujin1st commented 8 years ago

look if you set class in namespace section

yougeen commented 8 years ago

In which file do I need to set this? I used the snippets from the readme and created a Menu and MenuQuery Class and in both files I use creocoder\nestedsets\NestedSetsBehavior;

yujin1st commented 8 years ago

Where do you receive this error? What is shown in log?

yougeen commented 8 years ago

I created a sample Controller and call the model from this one.

The Log shows:

[error][yii\base\ErrorException:1] exception 'yii\base\ErrorException' with message 'Class 'creocoder\nestedsets\NestedSetsBehavior' not found' in /var/www/html/Yii2Dev/basic/models/Menu.php:22

Line 22 is 'class' => NestedSetsBehavior::className(),

   public function behaviors() {
        return [
            'tree' => [
                'class' => NestedSetsBehavior::className(),
                // 'treeAttribute' => 'tree',
                // 'leftAttribute' => 'lft',
                // 'rightAttribute' => 'rgt',
                // 'depthAttribute' => 'depth',
            ],
        ];
    }

the namespace I use in this model is:

namespace app\models; use Yii; use creocoder\nestedsets\NestedSetsBehavior;

And in my Controller likes like this:

namespace app\controllers;
use app\models\Menu;
use creocoder\nestedsets\NestedSetsQueryBehavior;

class MenuController extends \yii\web\Controller
{
    public function actionIndex()
    {
        $countries = new Menu(['name' => 'Countries']);
        $countries->makeRoot();

        return $this->render('index');
    }

}

Hope this helps you

kwazaro commented 8 years ago

Check the vendor folder for extension files, maybe this extension was installed incorrectly.