Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » How to call action from dataobject

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 1658 Views
  • Webdoc
    Avatar
    Community Member
    329 Posts

    How to call action from dataobject Link to this post

    Lets say that i have one page where is lot of sample models like bikes and so on they have all the same dataobject they are using lets say (bike).

    But there are lot of bike types like Supermoto, Street, Ebduro and so on. what i need to add in dataobject bike so i can tel the object in what product row it needs to be in holderpage of bikes

    Example using this thing: http://www.bmw.ee/Mudelivalik-34173cb38f07f89ddbebc2ac9128303f

    this is URL of holder page how it must be

    I understand that i need to add something like they are using in ecommerce for featuerd product or some enum field but lets say that i add enum field and in dataobject i choose what enum that or the other bike is but how to show them like so how to call the action to but the models to right row

  • UncleCheese
    Avatar
    4085 Posts

    Re: How to call action from dataobject Link to this post

    You wouldn't define that in the model. That's something that belongs in the controller for that holder page.

    Where are the categories defined in your model?

  • Webdoc
    Avatar
    Community Member
    329 Posts

    Re: How to call action from dataobject Link to this post

    nop i think i set them in my dataobject bike.php and use enum but how can i show them in the bike.ss so as they are in the website.
    not bike_show.ss

    if i add the enum i chooce some catecory from dropdown in dataobject and save it. but how can i make the ss to show them in right place like div called supermoto has all the bikes i have set supermoto. and so on.

  • Webdoc
    Avatar
    Community Member
    329 Posts

    Re: How to call action from dataobject Link to this post

    for example if i use in my data object:
    static $db = array(
    'BikeCategory' => "Enum('Enduro,Sport,tour')"
    );

    and it gives me the drop down in my dataobject how i call it to frontend to show me all the bikes choosed enduro are in enduro row and so on.

    what action i need to place in my pagetype bikelist.php and what is needed for bike.ss to show them

  • UncleCheese
    Avatar
    4085 Posts

    Re: How to call action from dataobject Link to this post

    Here's some pseudo code..

    public function Categories() {
    $ret = new DataObjectSet();
    foreach(singleton('Bike')->dbObject('BikeCategory')->enumValues() as $cat) {
    $ret->push(new ArrayData(array(
    'CategoryName' => $cat,
    'Bikes' => DataObject::get("Bike","BikeCategory = '$cat'")
    )));
    }
    }

    <% control Categories %>
    $CategoryName
    <% control Bikes %>
    $BikeField1 $BikeField2
    <% end_control %>
    <% end_control %>

  • Webdoc
    Avatar
    Community Member
    329 Posts

    Re: How to call action from dataobject Link to this post

    Didnt work i write u may code maybe u can tell whats wrong!

    Mootorrattas.php

    <?php
    class Mootorrattas extends DataObject
    {
       static $db = array (
       'MootorrattaCategory' => "Enum('Enduro,Sport,Tour,Racing')",
       'Mootorrattanimi' => 'Text',
       'Kirjeldus' => 'HTMLText',
       'Mootor' => 'Text',
       'Mootorivoimsus' => 'Text',
       'Poordemoment' => 'Text',
       'Surveaste' => 'Text',
       'Kytusesisselase' => 'Text',
       'Tippkiirus' => 'Text',
       'Sidur' => 'Text',
       'Kaivitussysteem' => 'Text',
       'Kaigukast' => 'Text',
       'Amordid' => 'Text',
       'Pidurid' => 'Text',
       'Rattad' => 'Text',
       'Istmekorgus' => 'Text',
       'Bensiinipaak' => 'Text',
       'Tyhimass' => 'Text',
       'Varvid' => 'Text',
       'Garantii' => 'Text',
       'Muuinfo' => 'Text',
       'Hind' => 'Text',
       'Soodushind' => 'Text',
       'Tahelepanu' => 'HTMLText',
       );
       static $has_one = array (
       'Mootorrattalist' => 'Mootorrattalist',
       'Photo' => 'Image'
       );
       static $has_many = array (
       'MootorrattasGalleryImages' => 'MootorrattasGalleryImage'
       );
       public function getCMSFields_forPopup()
       {
       return new FieldSet(
          new DropdownField('MootorrattaCategory','MootorrattaCategory',singleton('Mootorrattas')->dbObject('MootorrattaCategory')->enumValues()),
          new TextField('Mootorrattanimi', 'Mootorratta nimi'),
          new SimpleWysiwygField('Kirjeldus', 'Mootorratta kirjeldus'),
          new TextField('Mootor', 'Mootor'),
          new TextField('Mootorivoimsus', 'Mootori v&otilde;imsus'),
          new TextField('Poordemoment', 'P&ouml;&ouml;rdemoment'),
          new TextField('Surveaste', 'Surveaste'),
          new TextField('Kytusesisselase', 'K&uuml;tuse sisselase'),
          new TextField('Tippkiirus', 'Tippkiirus'),
          new TextField('Kaivitussysteem', 'K&auml;ivituss&uuml;steem'),
          new TextField('Sidur', 'Sidur'),
          new TextField('Kaigukast', 'K&auml;igukast'),
          new TextField('Amordid', 'Amordid'),
          new TextField('Pidurid', 'Pidurid'),
          new TextField('Rattad', 'Rattad'),
          new TextField('Istmekorgus', 'Istmek&otilde;rgus'),
          new TextField('Bensiinipaak', 'Bensiinipaak'),
          new TextField('Tyhimass', 'T&uuml;himass'),
          new TextField('Varvid', 'V&auml;rvid'),
          new TextField('Garantii', 'Garantii'),
          new TextField('Muuinfo', 'Muu info'),
          new TextField('Hind', 'Hind'),
          new TextField('Soodushind', 'Soodushind'),
          new SimpleWysiwygField('Tahelepanu', 'T&auml;helepaneku tekst'),
          new ImageField('Photo', 'Mootorratta pilt'),
       new ImageDataObjectManager(
          $this,
          'MootorrattasGalleryImages', // Source name
       'MootorrattasGalleryImage', // Source class
       'MootorrattasMyGalleryImage', // File name on DataObject
          array('MootorrattasGalleryImageTitle' => 'MootorrattasGalleryImageTitle')
          )
          );
       }
       function Link(){
          return $this->Mootorrattalist()->Link() .'show/'.$this->ID;
       }
       public function SuurHind() {
          return $this->Hind > 50000;
       }
    }
    ?>


    this is the dataobject

    Pagetype is Mootorrattalist.php:

    <?php
    class Mootorrattalist extends Page
    {
       static $has_many = array (
          'Mootorrattad' => 'Mootorrattas'
       );
       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $f->removeFieldFromTab("Root.Content.Main","Content");
          $manager = new DataObjectManager(
             $this, // Controller
             'Mootorrattad',
             'Mootorrattas',
             array(
             'Mootorrattanimi' => 'Mootorrattanimi'
             ),'getCMSFields_forPopup'
    );
    $f->addFieldToTab('Root.Content.Main', $manager);
    return $f;
       }
    }
    class Mootorrattalist_Controller extends Page_Controller
    {
    function show(){
    return array();
    }

    function Mootorrattas(){
    if(isset($this->request) && $this->request->param('ID')){
    return DataObject::get_by_id('Mootorrattas', (int)$this->request->param('ID'));
    }
    }
       public function Categories() {
       $ret = new DataObjectSet();
       foreach(singleton('Mootorrattas')->dbObject('MootorrattaCategory')->enumValues() as $cat) {
       $ret->push(new ArrayData(array( 'CategoryName' => $cat, 'bikes' => DataObject::get("Mootorrattas","MootorrattaCategory = '$cat'")
       )));
       }
       }
    }
    ?>

    and the .ss file:

    <% control Categories %>
    $CategoryName
    <% control bikes %>
    $MootorrattasField1 $MootorrattasField2
    <% end_control %>
    <% end_control %>

  • Webdoc
    Avatar
    Community Member
    329 Posts

    Re: How to call action from dataobject Link to this post

    can some one help an tell whats wrong why i dont see anything on my page

  • UncleCheese
    Avatar
    4085 Posts

    Re: How to call action from dataobject Link to this post

    What is this?

    $MootorrattasField1 $MootorrattasField2

    I don't see either of those fields on your "Mootorrattas" object..

    --------------------
    SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

    1658 Views
Page: 1 2
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.