Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Getting an ID to bass into get_by_id

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 311 Views
  • lozhowlett
    Avatar
    Community Member
    140 Posts

    Getting an ID to bass into get_by_id Link to this post

    Hi

    Let me start with my code

    public static $belongs_to = array(
    'Event' => 'Event',
    'Team' => 'Team'
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->removeFieldFromTab('Root.Content.Main', 'MenuTitle');
    $fields->removeFieldFromTab('Root.Content.Main', 'Title');
    $fields->removeFieldFromTab('Root.Content.Main', 'Content');

    $EventID = DataObject::get_by_id('Event',$this->EventID);

    $oData = (DataObject::get('Team','`Event_Teams`.EventID =' + $EventID,'','LEFT JOIN `Event_Teams` ON `Event_Teams`.TeamID=`Team`.ID ',''));
    if ($oData) {
    $CategoriesSource = $oData->toDropDownMap('ID','Name');
    } else {
    // no categories there yet, might put a literalfield to tell the user
    }

    What I am trying to do here is pass the EventID to the filter so I only see teams that are entered into the Event (by filter by eventID and then joining teams in the Event_teams table).

    However I get an error that EventID is null... (or to that effect)... I am not sure how to correctly reference EventID so that I get the current event thats selected in the CMS...

    Any ideas?

    Thanks

  • UncleCheese
    Avatar
    4085 Posts

    Re: Getting an ID to bass into get_by_id Link to this post

    What's the + for in your where clause?

  • lozhowlett
    Avatar
    Community Member
    140 Posts

    Re: Getting an ID to bass into get_by_id Link to this post

    disclaimer - im new to PHP, so i thought that would do the same as & in classic ASP... i didnt know how to include the variable in my select statement. So 2 probs here I guess...

    1. How do I get the ID
    2. How do i then include that in the where clause...

    thanks for any help or where I can go to find the right answer

    Cheers

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