1

I'm using the following Helper: http://pastebin.com/qBs2GvG4 in my CakePHP 2.0 app to show a gravatar for a user like so:

<?php $this->Gravatar->image($profile['User']['email'], array('default'=>'mm','size'=>48)); ?>

However it gives the error:

Fatal error: Call to a member function image() on a non-object in /Users/cameron/Sites/social/app/View/Helper/GravatarHelper.php on line 97

Any ideas what the problem is? This worked in my 1.3 app so wondering if something has changed between 1.3 and 2.0 that causes this issue? Thanks

5
  • Simply $this->Gravatar or $this is null while you call the method image. Commented Jan 25, 2012 at 23:35
  • Hi, not understanding the problem as the code is being executed from the Helper as if I comment out the return on line 97 it will load the page with no error (no gravatar though) so it defo gets to that Helper file fine so I don't see how it's null... Commented Jan 25, 2012 at 23:39
  • I don't know how it can be null with a one-line code but PHP output that message in that case. Commented Jan 25, 2012 at 23:40
  • Any updates? Really confusing :( Commented Jan 26, 2012 at 0:50
  • Make sure the gravatar helper extends the HtmlHelper. Commented Feb 1, 2012 at 10:58

2 Answers 2

1

Helpers have slightly different dependencies in 2.0, especially if they require other helpers.I actually made the commits to fix this one in the CakeDC utils plugin.

You can find an updated version of that helper here: https://github.com/CakeDC/utils/blob/2.0/View/Helper/GravatarHelper.php

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

2 Comments

Yeah I realised their was an updated version of the Helper yesterday which has solved the issue. Can you shed more light on what the issues were as I'm confused about what changed that broke it. Thanks
@Cameron the issue was that 2.0 helpers expect the View (and consequently other helpers) to be passed to them in their constructor.
0

Looks like the GravatarHelper has a dependency on the HtmlHelper. Is Html in your list of helpers in the controller?

2 Comments

Yes I have that in both the Helper and the global AppController
That's really weird. Line 97 says: return $this->Html->image($imageUrl, $options); which means that Html is not an object. Looking at the GravatarHelper you linked, it is including the Html helper correctly, so I'm not sure why it's not getting initialized.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.