This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hey Guys
I tried to make a plugin completly manually and with builder.
I always get this error message when trying to open tne cms part of the back end:
Class \Jonasgrunert\TestOnly\Components\Test does not exist
Im kinda confused, because this is my file structure:
jonasgrunert
--->testonly
------>components
--------->test
----------->default.htm
--------->Test.php
------>updates
---------->version.yaml
------>composer.json
------>Plugin.php
Plugin.php looks like this:
namespace jonasgrunert\TestOnly;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
public function pluginDetails()
{
return [
'name' => 'TestOnly',
'description' => 'Test Test Test',
'author' => 'jonasgrunert',
'icon' => 'icon-question'
];
}
public function registerComponents()
{
return [
'\Jonasgrunert\TestOnly\Components\Test' => 'Test'
];
}
}
And the Test.php like this:
namespace jonasgrunert\TestOnly\components;
class Test extends \Cms\Classes\ComponentBase
{
public function componentDetails()
{
return [
'name' => 'Test',
'description' => 'Just Testing Shit.'
];
}
}
Can anyone help me?
Last updated
I was able to naroow down the problems of the Code apparently something is incorrect with my path in registerComponents().
'\Jonasgrunert\TestOnly\Components\Test' => 'Test'
It works fine if I give any other path to another Plugin. When I do copy just another working class from another plugin into components and add it in register Components(), it won't work.
Therefore my question is the path casesensitive? or do I have to look at any other things?
Thanks in Advance
Last updated
Most likely an error in namespace. Try it
namespace Jonasgrunert\TestOnly;
namespace Jonasgrunert\TestOnly\Components;
jonas22863 said:
First of all Thank you for your answer. But unfortunatly it doesn't work.
@jonas22863 Were you able to find the cause of the error............... am facing a similar situation and I've gone over the code several times I don't know what am missing.
This worked for me:
- All my folder name are lowercase, same as @jonas22863
- All my class names and file names are the same, match each other and are CamelCased
- namespace and filepaths actually follow the same folder name convention ( I think its case sensitive here )
Here using @jonas22863 code
--namespace would be
namespace jonasgrunert\testonly;
Or
namespace jonasgrunert\testonly\components;
--filepath would be
return [ 'jonasgrunert\testonly\components\Test' => 'Test' ];
alex.migwi29876 said:
This worked for me:
- All my folder name are lowercase, same as @jonas22863
- All my class names and file names are the same, match each other and are CamelCased
- namespace and filepaths actually follow the same folder name convention ( I think its case sensitive here ) Here using @jonas22863 code --namespace would be
namespace jonasgrunert\testonly;
Or
namespace jonasgrunert\testonly\components;
--filepath would be
return [ 'jonasgrunert\testonly\components\Test' => 'Test' ];
Not sure if you got it working but your namespacing syntax is incorrect. As per PSR-1 coding standards, you need to use "StudlyCaps" and it should look more like this:
namespace JonasGrunert\TestOnly;
While registering your component it should also reflect this and look like this:
return [ 'JonasGrunert\TestOnly\Components\Test' => 'Test' ];
The most likely cause that your class can't be found is because your Windows machine is case sensitive while looking for a path while a unix system like Mac wouldn't care. The builder plugin might not take that into account but that is likely your issue.
Here are the coding standards to reference if you want to look them over. https://www.php-fig.org/psr/psr-1/
1-7 of 7