I hope the great SS team will include the "Add" methods.
Hope to share this code snippet to temporarily make the prototype work.
1. via Front end
a. Copy CSS into your local class
copy GridField.css to <<myclass>>.css
then replace ".cms table.ss-gridfield.field" with ".ss-gridfield.field"
b. Create html "Add" and "Print" html button
class <<myclasspage>>_Controller extends Page_Controller {
function Form() {
// Form name to be called in layout <formname>.ss or page.ss
$formName = 'Form';
// Create fields
$fields = $this->getCMSFields(); //<--- this includes the GridField
// Create actions
$addbtn = new FormAction('doAdd', 'Add'); //<--- this will be next to the Save button
$printbtn =new FormAction('doPrint', 'Print');
$actions = new FieldSet(array($addbtn,$printbtn));
// create the form
$form = new Form($this, $formName, $fields, $actions);
return $form;
}
function doAdd($data, $form) {
$this->redirect( "http://localhost/mydemo/myaddpage/" ); //<--- just a typical add form
return;
}
class MyAddPage_Controller extends Page_Controller {
public static $allowed_actions = array (
);
function init() {
parent::init();
Requirements::customCSS("#ModelAdminPanel {overflow:auto;}");
}
function Form() {
// Form name to be called in layout <formname>.ss or page.ss
$formName = 'Form';
// Create fields
$fields = Partners::getCMSFields();
// Create actions
$actions = new FieldSet(new FormAction('doSave', 'Save'));
// create the form
$form = new Form($this, $formName, $fields, $actions); //, $validator);
return $form;
}
function doSave($data, $form) {
$table = new MyClass(); //Setup class for Model DB
$form->saveInto($table); //Move Form fields into DB fields
$table->MyClassPageID = $this->dataRecord->ID;
$table->write();
$this->redirectback();
return;
}
2. via CMS backend
Add a new ModelAdmin
class <<myclassmodeladmin>> extends ModelAdmin {
public static $managed_models = array ('myclass');
static $url_segment = 'democlass';
static $menu_title = 'My Demo';