I want to create an EBay API wrapper object. In Rails, I would create a helper so it would be available in the controller and view. Where do I create such an object in Yii? There is no helpers/ directory. This was the closest concept I could find: http://www.yiiframework.com/doc-2.0/guide-structure-application-components.html
2
Answers
I managed to get this to work with the following, but I think there is a better answer.
helpers/myhelpers.php
views/shopping/index.php
For some reason, you have to still give the full namespace path to the function. It won't work without it.
You can always create a
helpers
directory if you want, there is nothing to stop you, just create your namespace accordingly. I personally put them in thecomponents
directory.You are using namespaces now 🙂 enjoy it. If you are using the advance app then there is already defined a namespace for the backend for example that is called….. backend. What does this mean it means that when you
use
a class that is found in a known namespace it starts from there and it tries to guess the path to your class.For example:
Bar should be found in the backend/helpers/foo directory. Yii2 will know where to find it because it knows where
backend
is.