Hi,
I need help.
Sorry for my bad English
I have site where when user regitering he could add Object do DataObject (by Frontend)
And here is the problem.
I want know who add Object - i must write to base current login user.
Generally I would do to the object added by the user was assigned to him
I have:
Page to Add Object
class AddOgloszeniePage extends Page
{
}
class AddOgloszeniePage_Controller extends Page_Controller
{
//Allow our form as an action
static $allowed_actions = array(
'OgloszenieForm'
);
//Generate the ogloszenia form
function OgloszenieForm()
{
$fields = singleton('Ogloszenie')->getFrontendFields();
$fields->removeByName('Member');
// Create action
$actions = new FieldSet(
new FormAction('doAdd', 'Add')
);
// Create action
$validator = new RequiredFields('Price');
return new Form($this, 'OgloszenieForm', $fields, $actions, $validator);
}
function doAdd($data,$form)
{
$Ogloszenie = new Ogloszenie();
$form->saveInto($Ogloszenie);
$Ogloszenie->write();
}
function Link() {
return $this->URLSegment;
}
}
My DataObject
<?php
class Ogloszenie extends DataObject
{
static $db = array(
'Title' => 'Varchar(255)',
'Description' => 'HTMLText',
'Price' => 'Decimal(6,2)',
'URLSegment' => 'Varchar(255)',
'MetaTitle' => 'Varchar(255)',
);
//Set our defaults
static $defaults = array(
'Title' => 'New Ogloszenie',
'URLSegment' => 'new-ogloszenie'
);
static $has_one = array(
'Image' => 'Image',
'Member' => 'Member'
);
.......
function getCMSFields()
{
$fields = parent::getCMSFields();
if($result = DataObject::get("Member")) {
$member_map = $result->toDropdownMap();
}
//Main Tab
$fields->addFieldToTab("Root.Main", new TextField('Title', 'Title'));
$fields->addFieldToTab("Root.Main", new TextField('URLSegment', 'URL Segment'));
$fields->addFieldToTab("Root.Main", new TextField('MetaTitle', 'Meta Title'));
$fields->addFieldToTab("Root.Main", new NumericField('Price'));
$fields->addFieldToTab("Root.Main", new HTMLEditorField('Description'));
$fields->addFieldToTab("Root.Main", new DropdownField('MemberID', 'Właściciel', $member_map ));
//Categories
$Categories = DataObject::get('CategoryPage');
$fields->addFieldToTab("Root.Categories", new CheckboxsetField('Categories', 'Categories', $Categories));
//Images
$fields->addFieldToTab("Root.Images", new ImageField('Image', 'Image', Null, Null, Null, 'Uploads/category_banners'));
return $fields;
}
......
}
And in Member DataObjectDecoration
<?php
class MemberDecorator extends DataObjectDecorator {
//Add extra database fields
public function extraStatics()
{
return array(
'db' => array(
....
),
'has_many' => array(
'Ogloszenia' => 'Ogloszenie'
)
);
}
......
}
I think I need to combine at this point but I have no more ideas
$Ogloszenie = new Ogloszenie();
$form->saveInto($Ogloszenie);
$Ogloszenie->write();
One more time, sorry for my bad English