This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
KurtJensen
Trying to put a trait in my plugin so I cam share common code between my components.
-
I created a Trait in october/plugins/kurtjensen/myplugin/traits/MyTrait.php
<?php namespace KurtJensen\MyPlugin\Traits; use Auth; use RainLab\User\Components\Account; use KurtJensen\MyPlugin\Models\Settings; trait MyTrait { public static $myarray = []; public function myFunction() { return array(1,2,3,4); } }
-
In my component october/plugins/kurtjensen/myplugin/components/MyComponent.php I did:
<?php namespace KurtJensen\MyPlugin\Components; use RainLab\Blog\Components\Post; class MyComponent extends Post { use MyTrait; // mycode }
I am getting error:
Trait 'KurtJensen\MyPlugin\Components\MyTrait' not found
I have tried changing namespace and moving traits folder around inside plugin but nothing I have tried seems to get this working. if I use:
use KurtJensen\MyPlugin\MyTrait;
I get:
Trait 'KurtJensen\MyPlugin\Components\KurtJensen\MyPlugin\MyTrait' not found
if I use:
use KurtJensen\MyPlugin\Traits\MyTrait;
I get:
Trait 'KurtJensen\MyPlugin\Components\KurtJensen\MyPlugin\Traits\MyTrait' not found
Last updated
Scott
It looks like you just forgot to add the leading backslash. Give this a try...
use \KurtJensen\MyPlugin\Traits\MyTrait;
Last updated
1-6 of 6