My original question on Stack Overflow
[http://stackoverflow.com/questions/21394852/whats-the-correct-method-for-using-traits-and-namespaces-for-cakephp-2],
and content copied here, should that disappear.
I'm using CakePHP 2.4.5 and PHP 5.5, and would like to use a trait.
I have a trait in Utility/VariablesTrait.php called VariablesTrait.
To take advantage of namespaces, I've given it a namespace of
App\Utility\VariablesTrait, since Utility\VariablesTrait seems a bit too
global, and the former would work better with CakePHP 3.
In my class that I want to use it in, I have the use
App\Utility\VariablesTrait; statement in the class. For backup, I also have
a App::uses('VariablesTrait', 'Utility'); statement at the top of the file.
I'm not sure if the SPL autoloader is used when looking for traits, which
is why I was going for namespaces in the first place.
The small issue is that the app directory is app, and since directory
structures should match namespaces (I think), I renamed it to App. However,
CakeRequest::_base() hardcodes app, so determining the controller doesn't
work so well.
So, I'm trying to determine if that's a CakePHP bug, or if there is a more
appropriate way of using traits in CakePHP 2.
Regards
Reuben Helms
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.