7912 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » DataObjectManager usage in frontend form
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1229 Views |
-
DataObjectManager usage in frontend form

4 March 2011 at 8:54am
Hi there, I'm trying to add the DOM functionality to a Frontend Form.
I want to give the logged in User to add some resources that belong to him.
The Resources are simple Dataobjects (in my case Customers, with Name, Address and Description).
Let me show you some code:
// The Member Decorator
class Account extends DataObjectDecorator {
public function extraStatics() {
return array(
'has_many' => array(
'Customers' => 'Customer'
)
);
}
public function getCustomers(){
return $this->owner->Customers();
}
}// the customer
class Customer extends DataObject {
static $db = array(
'Name' => 'Varchar',
'Address' => 'Text',
'Description' => 'Text'
);
static $has_one = array(
'Account' => 'Member'
);
function getCustomerFields_forPopup(){
return new FieldSet(
new TextField('Name'),
new TextareaField('Address'),
new TextareaField('Description')
);
}
}// the Page Object with the Form
class CustomersPage extends Page {
}class CustomersPage_Controller extends Page_Controller {
function init(){
parent::init();
}function CustomersForm(){
$Manager = new DataObjectManager(
$this,
'Customers',
'Customer',
array('Name' => 'Name'),
'getCustomerFields_forPopup',
'AccountID='.Member::currentUserID()
);
$Manager->setParentClass('Member');$fields = new FieldSet($Manager);
return new Form($this, 'CustomersForm', $fields, new FieldSet());
}
}So what happens:
When I open the CustomersPage, I can see the DOM. When Pressing on "Add Customer" not the Popup comes up, but a new site opens with the form that should normaly pop up. Sure, I can add Members there, but they are not associated with the current logged in Member. Instead AccountID shows 0.So my Question is, what do I have to do, to associate the saved Customer with the Current logged in Member ID and how can I receive the normal DOM behaviour like in the Backend Area with a popping up greybox or facebox or whatever DOM is using?
greetings
andre
-
Re: DataObjectManager usage in frontend form

17 March 2011 at 5:05am
Hi, I know it's been a while since opening of this thread, but I will try to wake it up again in hope, some may have an idea now, how to solve this Problem.
Regrads
Andre
-
Re: DataObjectManager usage in frontend form

5 April 2011 at 8:21pm
Hi Andre,
why your Add action opens in another window, I don't know, in my case it just happens as expected. As to why the new record does not get associated with the CurrentMember, I just hit the same problem... The solution was a call to setSourceID() as follows:
$Manager->setSourceID(Member::currentUserID());
HTH, cheers,
f.
| 1229 Views | ||
|
Page:
1
|
Go to Top |


