0

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

7
  • 2
    How did you name the helper file? Also, I'd avoid naming a helper "Helper", Cake may not like that... Commented Sep 4, 2012 at 20:36
  • Don't know if that is the source of your problem but IMO calling a helper 'helper' is kinda of asking for trouble· Commented Sep 4, 2012 at 20:37
  • thanks fir your comments, it was called something else previously and had the same problem :( Commented Sep 4, 2012 at 20:44
  • I named it supportHelper and FooHelper, still the same issue unfortunately :( Commented Sep 4, 2012 at 20:54
  • What version of cakephp are you using? Commented Sep 4, 2012 at 21:25

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.