Reputation: 426
I have a custom plugin called "MyApps". In MyApps I have Lib/MyCustomHelper.php.
I'm trying to access MyCustomHelper from a model function. I have no problem accessing in a controller.
In a controller, I would do this:
App::uses('MyCustomHelper', 'MyApps.Lib');
And then I could use it like this:
$myhelper = new MyCustomHelper();
Can anyone tell me how I can accomplish the same thing, but in a model class?
Upvotes: 0
Views: 149
Reputation: 25698
I could copy the whole text from my answer to this question How to load a component in console/shell and just replace component with helper. The answer would be the same, so please read it.
If you want to - and your text sounds like you already do - use helpers inside a controller you have a fundamental misunderstanding of how MVC works. They're not used inside a model nor a controller. They're supposed to work only inside the view layer.
If you can't get your current code to work without misusing the helper in the wrong context, your application architecture is already broken by design and you're on your way to create a pretty messy code base. You should fix your understanding of the MVC design pattern and then refactor the code.
Upvotes: 1