Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Text field bug

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 964 Views
  • Danix
    Avatar
    Community Member
    1 Post

    Text field bug Link to this post

    Hello, I have a problem adding a new

    TextField

    to a page. I have the following code:

    PortofoliuPage.php

    <?php


    class PortofoliuPage extends Page {


    static $db = array(


    );


    static $has_one = array(


    'Photo' => 'Image',


    'Desc' => 'Text'


    );


       

    function getCMSFields() {


    $fields = parent::getCMSFields();


    $fields->addFieldToTab("Root.Content.Images", new ImageField('Photo'));
    $fields->addFieldToTab("Root.Content.Images", new TextField('Desc'));
       
    return $fields;
    }
    }

    class PortofoliuPage_Controller extends Page_Controller {
       
    }
    ?>

    I flush the database and the admin panel. In the admin panel I add a PortofoliuHolder page. In the PortofoliuHolder page I add a PortofoliuPage.

    I add the details for PortofoiuPage, including an Photo and a Desc. I press the Save and Publish button. Now the problem:

    When I refresh the page, the information I entered in the Desc field dissapears
    (The photo don't)

    I looked in the database in the PortofoliuPage table, and there are two columns there: an id for the photo and an id for the Desc (0 value).

    Note that I tried to drop the entire database and create it again.

    A bug in the CMS? Am I mistaking? Please help me!

    Thanks,
    Danix
    redarts

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Text field bug Link to this post

    You're making a mistake.

    if you use a $has_one relationship, you should make another object at the other side too.
    If you want only one field, the 'desc', you have to add it to the $db array.

    Like:

    static $db = array("Desc" => "Text" );

    The image is in a $has_one relationship because it resides in a different table, the file-table.

    But I think it would be better to make a $has_many relationship and create a separate $Project DataObject.

    I suggest you read through some more documentation:

    http://doc.silverstripe.com/doku.php?id=datamodel#Relations
    http://doc.silverstripe.com/doku.php?id=tutorial:5-dataobject-relationship-management

    Hope this helped.

    964 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.