Problem with component class

Notice: This thread is very old.
ruben_cgt
Member | 6
+
0
-

Hello guys I have a little problem here

I have in the presenter declared the component like this

protected function createComponentNavigation($name)
	{
		$nav = new Navigation($this, $name);
	}

and I am calling the navigation in the .latte like this

{widget navigation}

the class is located in the directory
libs\Nmaster\Navigation.php

and I am getting this error Class ‘Navigation’ not found I don't see where is the error can any of you help me please

jiri.pudil
Nette Blogger | 1028
+
0
-

First of all, what version of Nette are you using? In newer versions, widget macro has been deprecated and it is recommended to use control instead:

{control navigation}

Also, passing the arguments in constructor is not necessary, so this will suffice:

protected function createComponentNavigation()
{
    $nav = new Navigation;
    return $nav;
}

Note that the factory method has to return the created component.

As to your actual problem :) I guess it is a namespace issue. If the Navigation class is in a different namespace from the presenter, you should add a use statement for it into the presenter. Otherwise, it might help to clear the cache (contents of temp/cache/).

ruben_cgt
Member | 6
+
0
-

Thank you very much for the rapid feedback Jiri. it seems to be a namespace issue now I have it like this and I have the folder with class under libs/Navigation but still nette can't find the class I also tried erasing the cache

libs/NavigationPlugin
{control navigation}
protected function createComponentNavigation()
{
    $nav = new NavigationPlugin/Navigation;
    return $nav;
}
hAssassin
Member | 293
+
0
-

Hi, try absolute namespace like this: $nav = new \NavigationPlugin\Navigation; and keep in mind, that the namespace separator is \ (backslash), not / like folder separator.

ruben_cgt
Member | 6
+
0
-

thank you very much! such a stupid mistake.. is working now