MarcC Posted January 18, 2012 Share Posted January 18, 2012 I'm seeing this error in the logs: 2012-01-18 09:23:37: guest:/pagename/:Error:Call to a member function width() on a non-object (line 57 of /home/blah/public_html/site/templates/sidebar.inc.php) Here's the code in question: (56) $newsletter = $pages->get('/'); (57) $newsThumb = $newsletter->sidebar_image->width(155); The sidebar seems to render OK, there's an image in the field in question, and it is being resized properly. But I fear my way of getting the page or image is a bit off. Thanks Link to comment Share on other sites More sharing options...
apeisa Posted January 18, 2012 Share Posted January 18, 2012 Looks good to me. That code should work if sidebar image is single image field. If not, then you need to grab first() image. Link to comment Share on other sites More sharing options...
MarcC Posted January 18, 2012 Author Share Posted January 18, 2012 Yep, it's a single image field. Weird, not sure why the error then. Link to comment Share on other sites More sharing options...
Soma Posted January 18, 2012 Share Posted January 18, 2012 Maybe try a var_dump on $newsletter->sidebar_image or alike to track down the problem Link to comment Share on other sites More sharing options...
apeisa Posted January 18, 2012 Share Posted January 18, 2012 The error is only once in logs or still occur? Link to comment Share on other sites More sharing options...
MarcC Posted January 18, 2012 Author Share Posted January 18, 2012 Three times in logs in the last day. I found out about it via automated error email from the site. Link to comment Share on other sites More sharing options...
jan Posted August 5, 2012 Share Posted August 5, 2012 Hi there, don't know if there's already a solution. I was trying the following: $image = $blog_entry->blog_images->first(); $blog_thumb = $image->width(500); As result I get: Error Call to a member function width() on a non-object As I found out, the $image object seems to be returned propably. Any ideas, what's going on? Thanks for your replies in advance!! Link to comment Share on other sites More sharing options...
JeffS Posted August 6, 2012 Share Posted August 6, 2012 @jan Are you using the new blog profile or did you set the value of $blog_entry in your own code in this template? Here is an example using a normal wire $page array <?php // get the image $page if your talking normal pw. If your using the blog profile then .. $image = $page->blog_images->first(); // check to see if you have an image if ($image) { // set the image size (crop to 500x500) $blog_thumb = $image->width('500'); // output your image echo "<img src='{$blog_thumb}>"; } Link to comment Share on other sites More sharing options...
jan Posted August 6, 2012 Share Posted August 6, 2012 @JeffS Thanks a lot for your replay. Im not using the new blog profile. Here's some more code. I'm using something similar on another page and everthing works fine. I can't see a difference. Can you find any mistakes?! $blog_entries = $pages->get("id=1008")->children; foreach($blog_entries as $blog_entry) { $image = $blog_entry->blog_images->first(); $blog_thumb = $image->width('500'); echo "<div class='blog_overview_item' >"; echo "<h2><a href=\"{$blog_entry->url}\">{$blog_entry->title}</a></h2>"; echo "<p>posted on ". date("d.m.Y, H:i", $blog_entry->created) ."</p>"; echo '<div class="blog_preview_image">'; echo "<a href='{$blog_entry->url}'><img width='{$blog_thumb->width}' height='{$blog_thumb->height}' src='{$blog_thumb->url}' alt='{$blog_thumb->description}' /></a>"; echo "</div>"; echo "</div>"; } If I remove resizing of the image, everything works fine. If I try $image->width('500'); or $image->size(500, 500); I get the error. Any ideas? Link to comment Share on other sites More sharing options...
Pete Posted August 6, 2012 Share Posted August 6, 2012 Remove the single quotes around the 500 maybe? It's expecting an integer and in quotes you're passing it as a string. Oh, then I read the next bit where you did it without quotes and it was no better... Link to comment Share on other sites More sharing options...
Soma Posted August 6, 2012 Share Posted August 6, 2012 @JeffS Thanks a lot for your replay. Im not using the new blog profile. Here's some more code. I'm using something similar on another page and everthing works fine. I can't see a difference. Can you find any mistakes?! $blog_entries = $pages->get("id=1008")->children; foreach($blog_entries as $blog_entry) { $image = $blog_entry->blog_images->first(); $blog_thumb = $image->width('500'); echo "<div class='blog_overview_item' >"; echo "<h2><a href=\"{$blog_entry->url}\">{$blog_entry->title}</a></h2>"; echo "<p>posted on ". date("d.m.Y, H:i", $blog_entry->created) ."</p>"; echo '<div class="blog_preview_image">'; echo "<a href='{$blog_entry->url}'><img width='{$blog_thumb->width}' height='{$blog_thumb->height}' src='{$blog_thumb->url}' alt='{$blog_thumb->description}' /></a>"; echo "</div>"; echo "</div>"; } If I remove resizing of the image, everything works fine. If I try $image->width('500'); or $image->size(500, 500); I get the error. Any ideas? Any more informations? Does it fail on all or just on some. What line is the error? You could try this modified code: <?php $blog_entries = $pages->get(1008)->children; foreach($blog_entries as $blog_entry) { $blog_thumb = false; if(count($blog_entry->blog_images)){ if($blog_entry->blog_images->first()) { $image = $blog_entry->blog_images->first(); } else $image = $blog_entry->blog_images; $blog_thumb = $image->width(500); } echo "<div class='blog_overview_item' >"; echo "<h2><a href=\"{$blog_entry->url}\">{$blog_entry->title}</a></h2>"; echo "<p>posted on ". date("d.m.Y, H:i", $blog_entry->created) ."</p>"; echo '<div class="blog_preview_image">'; if($blog_thumb) { echo "<a href='{$blog_entry->url}'><img width='{$blog_thumb->width}' height='{$blog_thumb->height}' src='{$blog_thumb->url}' alt='{$blog_thumb->description}' /></a>"; } echo "</div>"; echo "</div>"; } Link to comment Share on other sites More sharing options...
jan Posted August 6, 2012 Share Posted August 6, 2012 Oh sh**. I'm sorry. I found my mistake and it's really more than simple! I made two new entries in Processwire backend to test the blog. One of these two entries had images, the other didn't have any... So thanks @Soma you were on the right track! I just tried to change size of an image that was not there. Surprise! Ok after all, thanks for your effort!!! *embarrassing* Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now