# |
Jul 23rd 2018, 22:36 |
mdotobie |
Got it working @saeideng |
# |
Jul 23rd 2018, 22:19 |
saeideng |
after `composer dump-autoload ` |
# |
Jul 23rd 2018, 22:18 |
saeideng |
it should work |
# |
Jul 23rd 2018, 22:17 |
mdotobie |
Yes |
# |
Jul 23rd 2018, 22:17 |
saeideng |
and in this folder `plugins/cakephp-datadog/src/App/Services/DataDogService.php` |
# |
Jul 23rd 2018, 22:16 |
saeideng |
`namespace CakePHP_DataDog\App\Services\DataDogService` |
# |
Jul 23rd 2018, 22:16 |
saeideng |
your name space in plugin is |
# |
Jul 23rd 2018, 22:14 |
mdotobie |
If do a use statement ‘CakePHP_DataDog\App\Services\DataDogService’ I get a class not found |
# |
Jul 23rd 2018, 22:13 |
mdotobie |
So for instance, I have a class called DataDogService within the plugin under the namespace /App/Services |
# |
Jul 23rd 2018, 22:13 |
saeideng |
https://book.cakephp.org/3.0/en/plugins.html#manually-autoloading-plugin-classes |
# |
Jul 23rd 2018, 22:12 |
mdotobie |
Because it’s not identifying the namespacing within the plugin |
# |
Jul 23rd 2018, 22:12 |
mdotobie |
That’s the part not working |
# |
Jul 23rd 2018, 22:12 |
saeideng |
you no need to `Plugin.php` in this plugin |
# |
Jul 23rd 2018, 22:12 |
mdotobie |
Okay I see what you mean now |
# |
Jul 23rd 2018, 22:11 |
mdotobie |
So I have to call the classes inside the plugin from the Plugin.php |
# |
Jul 23rd 2018, 22:10 |
mdotobie |
Plus it was a good way to dive into developing plugins |
# |
Jul 23rd 2018, 22:10 |
mdotobie |
I envision the functionality might be helpful for future projects |
# |
Jul 23rd 2018, 22:09 |
saeideng |
of course Plugins is good place for your codes |
# |
Jul 23rd 2018, 22:09 |
saeideng |
without any problem and needing to composer |
# |
Jul 23rd 2018, 22:08 |
saeideng |
you can work in folder under `src` |
# |
Jul 23rd 2018, 22:08 |
saeideng |
and why in Plugins folder ? |
# |
Jul 23rd 2018, 22:07 |
saeideng |
just make sure your plugin files loaded successfully by composer , not `$this->addPlugin...` |
# |
Jul 23rd 2018, 22:06 |
saeideng |
`new yourclass()` |
# |
Jul 23rd 2018, 22:06 |
saeideng |
`use CakePHP_DataDog\yourclass` |
# |
Jul 23rd 2018, 22:05 |
saeideng |
for class |
# |
Jul 23rd 2018, 22:05 |
saeideng |
and for model/ behavior/ ..... |
# |
Jul 23rd 2018, 22:04 |
saeideng |
for controller you must extent main/your controller from plugin controller |
# |
Jul 23rd 2018, 22:03 |
mdotobie |
lets say I have a class, not a model or controller or anything like that, just a class inside the plugin that I want to instantiate |
# |
Jul 23rd 2018, 22:03 |
mdotobie |
But, I can’t figure out how to access plugin resources inside say a main application controller |
# |
Jul 23rd 2018, 22:02 |
mdotobie |
and I can confirm thats working |
# |
Jul 23rd 2018, 22:02 |
saeideng |
just `$this->addPlugin('cakephp-datadog');` |
# |
Jul 23rd 2018, 22:02 |
mdotobie |
so yes I know I can get rid of that |
# |
Jul 23rd 2018, 22:02 |
mdotobie |
that’s how I was originally loading the plugin |
# |
Jul 23rd 2018, 22:02 |
saeideng |
you nno need to this class |
# |
Jul 23rd 2018, 22:02 |
saeideng |
https://github.com/cakephp/debug_kit/blob/master/src/Plugin.php |
# |
Jul 23rd 2018, 22:01 |
saeideng |
so why are u using `use CakePHP_DataDog\Plugin as DataDog;` ?? |
# |
Jul 23rd 2018, 22:00 |
mdotobie |
no I don’t have a class called plugin |
# |
Jul 23rd 2018, 22:00 |
mdotobie |
I was under the impression that I could use Plugin syntax to reference plugin resources |
# |
Jul 23rd 2018, 21:59 |
mdotobie |
now lets say I have a method in the `Plugin.php` file called `info()`. I can only get it to run by declaring a use statement again and then created a new instance |
# |
Jul 23rd 2018, 21:59 |
saeideng |
do you have `Plugin` class ? |
# |
Jul 23rd 2018, 21:58 |
saeideng |
$this->addPlugin('cakephp-datadog'); |