Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

array_flip() [function.array-flip]: The argument should be an array


Go to End
Reply


2 Posts   697 Views

Avatar
lozhowlett

Community Member, 151 Posts

21 October 2011 at 4:50am

Hi everyone

I am getting an error:

array_flip() [function.array-flip]: The argument should be an array

This is when trying to save a "Result" from the code below...

<?php
class Result extends DataObject {

	public static $db = array(
            'PositionFinished' => 'Int',
            'PointedScored' => 'Int',
            'isFastestLap' => 'Boolean'
	);

	static $has_many = array (
	);
      
         public static $belongs_to = array( 
            'Event' => 'Event',
            'Team' => 'Team'
        );
        
        function getCMSFields_forPopup() {
            $fields = new FieldSet();
            //$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 ','')); 
            $oData = (DataObject::get('Team','','','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  
            }
            $dropdown = new DropdownField('TeamID', 'Team', $CategoriesSource, $this->TeamID); 
            $fields->push($dropdown);
            $fields->push(new NumericField('PositionFinished'));
            $fields->push(new NumericField('PointedScored'));
            $fields->push(new CheckboxField('isFastestLap'));
            return $fields;
        }
}

<?php
class Event extends Page {

	public static $db = array(
            'Date' => 'Date',
            'Time' => 'Time',
            'isNextRace' => 'Boolean'
	);

        static $has_one = array (
            //'Track' => 'Track'
        );
        
	static $has_many = array (
            'ImageResources' =>'ImageResource',
            'Results' => 'Result'
	);
        
        public static $many_many = array( 
            'Teams' => 'Team'
        );
        
        function getCMSFields() {
            $fields = parent::getCMSFields();
            $fields->addFieldToTab("Root.Content.Main", new DatePickerField('Date'));
            $fields->addFieldToTab("Root.Content.Main", new TimeField('Time'));
            $fields->addFieldToTab("Root.Content.Main", new CheckboxField('isNextRace'));
            
            
            $tablefield = new ManyManyComplexTableField(
                 $this,
                 'Teams',
                 'Team',
                 array(
                 'Name' => 'Name',
                 'CarNumber' => 'CarNumber'
                 ),
                 'getCMSFields_forPopup'
             );
            $fields->addFieldToTab("Root.Content.Team Manager",$tablefield);
            
            $tablefield = new ComplexTableField(
                 $this,
                 'Results',
                 'Result',
                 array(
                 'PositionFinished' => 'PositionFinished',
                 'PointedScored' => 'PointedScored',
                 'CarNumber' => 'CarNumber'
                 ),
                 'getCMSFields_forPopup'
             );
            $fields->addFieldToTab("Root.Content.Result Manager",$tablefield);
            
            $managerimages = new ImageDataObjectManager(
                    $this, // Controller
                    'Images', // Source name
                    'ImageResource', // Source class
                    'Attachment', // File name on DataObject
                    array(
                        'Title' => 'Title'
                    ), // Headings 
                    'getCMSFields_forPopup' // Detail fields
                    // Filter clause
                    // Sort clause
                    // Join clause
                );
                $fields->addFieldToTab("Root.Content.Image Gallery",$managerimages);

            return $fields;
        }

}
class Event_Controller extends Page_Controller {
	public static $allowed_actions = array (
	);

	public function init() {
            parent::init();
	}
}

<?php
class Team extends Page {

	public static $db = array(
            'Name' => 'Text',
            'CarNumber' => 'Text',
            "Class" => "Enum('Petrol, Diesel', 'Diesel')",
            'ContactTelephone' => 'Text',
            'ContactEmail' => 'Text',
            'CarLocation' => 'Text'
	);

	static $has_many = array (
            'ImageResources' =>'ImageResource',
            'Drivers' => 'Driver',
            'Results' => 'Result'
	);
        
        static $allowed_children = array('Driver');
        static $default_child = "Driver";

        public static $belongs_many_many = array( 
            'Events' => 'Event',
        );
        
        public static $has_one = array(
            'ProfilePicture' => 'Image'
	);
        
        function getCMSFields() {
            $fields = parent::getCMSFields();
            $fields->addFieldToTab("Root.Content.Main", new TextField('Name'));
            $fields->addFieldToTab("Root.Content.Main", new TextField('CarNumber'));
            $fields->addFieldToTab("Root.Content.Main", new TextField('ContactTelephone'));
            $fields->addFieldToTab("Root.Content.Main", new TextField('ContactEmail'));
            $fields->addFieldToTab("Root.Content.Main", new TextField('CarLocation'));
            $fields->addFieldToTab("Root.Content.Main", new ImageField('ProfilePicture'));
            $fields->addFieldToTab("Root.Content.Main", new DropdownField('Class', 'Class', singleton('Team')->dbObject('Class')->enumValues()));
            $managerimages = new ImageDataObjectManager(
                    $this, // Controller
                    'Images', // Source name
                    'ImageResource', // Source class
                    'Attachment', // File name on DataObject
                    array(
                        'Title' => 'Title'
                    ), // Headings 
                    'getCMSFields_forPopup' // Detail fields
                    // Filter clause
                    // Sort clause
                    // Join clause
                );
                $fields->addFieldToTab("Root.Content.Image Gallery",$managerimages);

            return $fields;
        }

}
class Team_Controller extends Page_Controller {
	public static $allowed_actions = array (
	);

	public function init() {
            parent::init();
	}
}

Really stuck on this, any help would be great! Or just how I might go about debugging it more?

Oddly it saves the Finish position and the points scored, so I presume it s problem with the relationship to the TeamID, therefore I think its saving the EventID, just not the TeamID?

Thanks! :)

Avatar
lozhowlett

Community Member, 151 Posts

28 October 2011 at 1:52am

Bump! :)

Anyone got a clue for me? THanks