Jump to:

3449 Posts in 1063 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Call to undefined method DataObject::image()

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1242 Views
  • warden
    Avatar
    Community Member
    2 Posts

    Call to undefined method DataObject::image() Link to this post

    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()

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: Call to undefined method DataObject::image() Link to this post

    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.

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: Call to undefined method DataObject::image() Link to this post

    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.

  • warden
    Avatar
    Community Member
    2 Posts

    Re: Call to undefined method DataObject::image() Link to this post

    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.

    1242 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.