Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Need help to show dataobject on page

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3 4
Go to End
Author Topic: 2528 Views
  • Webdoc
    Avatar
    Community Member
    332 Posts

    Re: Need help to show dataobject on page Link to this post

    gives error something is wrong

  • theoldlr
    Avatar
    Community Member
    103 Posts

    Re: Need help to show dataobject on page Link to this post

    I am having some trouble with this too. I'm guessing that Webdoc is also using these tutorials...

    http://www.ssbits.com/using-silverstripe-url-parameters-to-display-dataobjects-on-a-page/
    http://www.ssbits.com/display-dataobjects-in-an-seo-friendly-way/

    I looked at the comment made on the 2nd linked page about using the SEO friendly version on 2.4 but I'm not understanding exactly how this additional code fits in to the entire implementation.

    Here is my code thus far:

    UsedEquip.php

    class UsedEquip extends DataObject{

    static $db = array (
    'Name' => 'Text',
    'Description' => 'Text',
    'Material' => "Enum('Mild Steel,Stainless Steel','Mild Steel')",
    'Tanks' => 'Text',
    'MaterialHandling' => "Enum('Conveyor,Drum,Monorail','Conveyor')",
    'URLSegment' => 'Varchar(255)'
    );

    static $has_one = array (
    'UsedEquipPage' => 'UsedEquipPage',
    'Photo' => 'Image'
    );

    public function getCMSFields_forPopup()
    {
    return new FieldSet(
    new TextField('Name','Name'),
    new SimpleHTMLEditorField('Description'),
    new DropdownField(
    $name = "Material",
    $title = "Made From",
    $source = singleton('UsedEquip')->dbObject('Material')->enumValues()
    ),
    new TextField('Tanks','No. of Tanks'),
    new DropdownField(
    $name = "MaterialHandling",
    $title = "Material Handling",
    $source = singleton('UsedEquip')->dbObject('MaterialHandling')->enumValues()
    ),
    new ImageField('Photo')

    );
    }
    function Thumbnail() {
    $Photo = $this->Photo();
    if ( $Photo ) {
    return $Photo->CMSThumbnail();
    } else {
    return null;
    }
    }

    //This function doesnt work with the Name property defined as Varchar--I changed it to Text, but now URLSegments are always
    //numbers
    public function onBeforeWrite(){
    if($this->Name){
    $this->URLSegment = SiteTree::GenerateURLSegment($this->Name);
    if($object = DataObject::get_one($this->ClassName, "URLSegment='" .$this->URLSegment
    ."' AND ID !=".$this->ID)){
    $this->URLSegment = $this->URLSegment.'-'.$this->ID;
    }
    else {
    $this->URLSegment = SiteTree::GenerateURLSegment($this->ClassnName.'-'.$this->ID);
    }
    parent::onBeforeWrite();
    }
    }

    }

    class UsedEquip_Controller extends Controller{
    }

    UsedEquipPage.php

    class UsedEquipPage extends Page{

    static $has_many = array (
    'UsedEquips' => 'UsedEquip'
    );

    public function getCMSFields()
    {
    $fields = parent::getCMSFields();
    $manager = new DataObjectManager(
    $this, // Controller
    'UsedEquips', // Source name
    'UsedEquip', // Source class
    array(
    'Name' => 'Name',
    'Description' => 'Description',
    'Material' => 'Material',
    'Tanks' => 'Tanks',
    'MaterialHandling' => 'MaterialHandling',
    'Thumbnail' => 'Photo',
    'URLSegment' => 'URLSegment'
    ), // Headings
    'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
    // Filter clause
    // Sort clause
    // Join clause
    );

    $fields->addFieldToTab("Root.Content.Equipment",$manager);
    return $fields;
    }

    }

    class UsedEquipPage_Controller extends Page_Controller{
    function init(){
    Requirements::javascript("http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js");
    if(Director::is_ajax() /*|| $_GET["ajaxDebug"]*/) {
    $this->isAjax = true;
    }
    else{
    $this->isAjax = false;
    }
    parent::init();
    }

    public function getIndividualEquip(){
    if($URLAction = Director::URLParam('Action')){
    $EquipURLSegment = Convert::raw2xml($URLAction);
    if($EquipURLSegment){
    return DataObject::get_one('UsedEquip',"URLSegment='".$EquipURLSegment."'");
    }
    }
    }

    }

    Any Help much appreciated!

  • Webdoc
    Avatar
    Community Member
    332 Posts

    Re: Need help to show dataobject on page Link to this post

    enum cant be translated but i made it myself easier just added the enums like so:

    'Elamutyyp' => "Enum('Korter, Maja, Aripind, Suvila, Ridaelamu, Paarismaja, Maatykk, Kerrostalo_osake, Omakotitalo, Liiketila, Kesamokki, Rivitalo, Paritalo, Tontti')",

    here are both estonian and finnish language and in template for search used:

    $form->disableSecurityToken();

    so i was able to made my own costum search without needing securityID

    2528 Views
Page: 1 2 3 4
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.