AndrewSimm
Well-known member
I asked this question on the demo board, but the board was closed before I could get an answer I understand.
Below is my entity that i am trying to insert into. The form needs to be available for any registered user. I am trying to figure out the XF2 way of doing things. Using procedural PHP it isn't very difficult to do a prepared statement. I am just a little confused on what I need to put into my controller (I assume the same controller as the page) to insert new records into the database.
Can someone give me a quick sample on how I would do this?
Below is my entity that i am trying to insert into. The form needs to be available for any registered user. I am trying to figure out the XF2 way of doing things. Using procedural PHP it isn't very difficult to do a prepared statement. I am just a little confused on what I need to put into my controller (I assume the same controller as the page) to insert new records into the database.
Can someone give me a quick sample on how I would do this?
PHP:
class Predictions extends \XF\Mvc\Entity\Entity
{
public static function getStructure(Structure $structure)
{
$structure->table = 'player_predictions';
$structure->shortName = 'XF:Predictions';
$structure->primaryKey = 'prediction_id';
$structure->columns = [
'prediction_id' => ['type' => self::UINT, 'autoIncrement' => true, 'changeLog' => false],
'user_id' => ['type' => self::UINT, 'maxLength' => 8, 'changeLog' => false],
'player_id' => ['type' => self::UINT, 'maxLength' => 8, 'changeLog' => false],
'man_college_id' => ['type' => self::UINT, 'maxLength' => 4, 'changeLog' => false],
'confidence' => ['type' => self::STR, 'maxLength' => 64, 'default' => '', 'changeLog' => false],
'date_added' => ['type' => self::STR, 'default' => '', 'changeLog' => false]
];
$structure->getters = [
'date' => true
];
$structure->relations = [
'Player' => [
'entity' => 'CIS\Backend:Player',
'type' => self::TO_ONE,
'conditions' => 'player_id',
'primary' => true
],
'CollegeTeam' => [
'entity' => 'CIS\Backend:CollegeTeam',
'type' => self::TO_ONE,
'conditions' => 'man_college_id',
'primary' => true
],
'User' => [
'entity' => 'XF:User',
'type' => self::TO_ONE,
'conditions' => 'user_id',
'primary' => true
]
];
return $structure;
}
//Get date
public function getDate()
{
$string = date_create($this->date_added);
return date_format($string,"M d, Y");
}
}