Reputation: 7056
I'm trying to work out why my helper isn't being found in my controller.
I'm getting the following error:
Fatal error: Call to a member function hash() on a non-object in /home/example/public_html/cake/app/Controller/CommentsController.php on line 26
This is my "helper" helper found in views/helpers
class HelperHelper extends AppHelper {
public function hash($hash){
return md5(sha1($hash."sha1777")."md5888");
}
...
this is the commentscontroller:
class CommentsController extends AppController {
public $helpers = array('Html', 'Form', 'Helper');
$chk = $this->Helper->hash($this->request->data["Comment"]["qid"].$this->request->data["Comment"]["aid"]);
I can see the helper listed when I do the following just before:
When I print the helpers I can see it in the array:
Array
(
[0] => Html
[1] => Form
[2] => Helper
)
I don't understand why this isn't working... any help would be much appreciated.
Many thanks, Tim
Upvotes: 0
Views: 610
Reputation: 14175
Oh, I got this one! Your helper isn't being found by your controller because helpers are extensions for the View layer. Components are the extensions of the Controller layer.
So if you want to use this helper in the controller as you trying, make it a component instead. Or move the formatting code to the view if it is formatting code.
Upvotes: 2