3060 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1069 Views |
-
Call to undefined method DataObject::image()

26 January 2010 at 11:02pm Last edited: 26 January 2010 11:03pm
Hi,
i try to output a default image if no image is set:
class myclass extends DataObject {
static $has_one = array(
'Image' => 'Image'
);public function Image()
{
if($this->ImageID) return parent::Image();
else return File::find('assets/default.png');
}
}On my local machine it works fine, but on webserver i get the mesasge
Call to undefined method DataObject::image() -
Re: Call to undefined method DataObject::image()

27 January 2010 at 4:44am Last edited: 27 January 2010 5:11am
I would realize this via the template:
<% control myclass %>
<% if Image %>
$Image
<% else_if %>
[hardcoded Link]
<% end_if %>
<% end_control %>
With "parent::Image()" you´re infact calling DataObject::Image() which does not exist. -
Re: Call to undefined method DataObject::image()

27 January 2010 at 5:41am
The template error was due to an error in the nested conditionals in the layout/ChatPage.ss tempate. I changed it and appended it to this post.
-
Re: Call to undefined method DataObject::image()

27 January 2010 at 8:09am Last edited: 27 January 2010 8:09am
I would realize this via the template:
I think this is not really comfortable. Because my posted code is only an example.
In real code there are two default images. One for male and another one for female users.
And the myclass is a user-management class. The Image is called in many Templates. And often with different sizes using $Image.setWidth(xx)With "parent::Image()" you´re infact calling DataObject::Image() which does not exist.
But I'm wondering why this works on my local machine. (php Version 5.2.10).
But same Code on my Webserver (php Version 5.2.0-8) causes this error.
| 1069 Views | ||
|
Page:
1
|
Go to Top |


