Ok, have been working on it and it is going well. ModelAdmin has been able to provide many of the features that i need, but now i need to start using routing and that is getting a bit more complex.
I have set up a controller under mysite/controllers called customer.php (mysite/controllers/customer.php) with a corresponding model under mysite/models/customer.php.
mysite/models/customer.php looks like this:
--------------------------------------------------------
class Customer extends DataObject {
public static $db = array(
'SiteRand'=> 'Varchar(20)',
'Name'=>'Varchar(255)',
'Surname'=>'Varchar(255)',
'DateJoined'=>'Date',
'Tel1'=>'Varchar(10)',
'Tel2'=>'Varchar(10)',
'Tel3'=>'Varchar(10)',
'Email1'=>'Varchar(255)',
'Email2'=>'Varchar(255)',
'Fax'=>'Varchar(6)',
'IDNumber'=>'Varchar(20)',
'Address'=>'Varchar(255)',
'IsActive'=>'Boolean'
);
public static $has_one = array(
'PostalCodes'=>'PostalCode'
);
mysite/controllers/customer.php looks like this:
----------------------------------------------------------
class Customer_Controller extends Controller {
public static $allowed_actions = array ('CustomerForm','customer');
public function init() {
parent::init();
}
//RENDER THIS CONTROLLER WITH 'PAGE' TEMPLATE
public function index() {
return $this->renderWith("Page");
}
//CREATE CUSTOMER FORM
public function CustomerForm() {
return BootstrapForm::create(
$this,
"CustomerForm",
FieldList::create(
HiddenField::create("SiteRand","", date("YmdHis")."-".rand(99,10000)),
TextField::create("Name","Name")
->addExtraClass("required"),
TextField::create("Surname","Surname")
->addExtraClass('required'),
NumericField::create("IDNumber","ID Number")
->setMaxLength('13'),
NumericField::create("Tel1","Phone number 1")
->addExtraClass("required")
->setMaxLength('10'),
NumericField::create("Tel2","Phone number 2")
->setMaxLength('10'),
NumericField::create("Tel3","Phone number 3")
->setMaxLength('10'),
EmailField::create("Email1","Email address 1"),
EmailField::create("Email2","Email address 2"),
DateField::create("DateJoined","Date Added")
->setConfig('showcalendar', true)
->addExtraClass('datepicker')
->setValue (date('Y/m/d'))
->setConfig('min', '2013-01-01'),
CheckboxField::create("IsActive","Is client active?", "True"),
TextareaField::create("Address","Physical Address")
->setAttribute('maxlength',200),
ChosenDropdownField::create("PostalCodesID", "Postal Addres")
->setSource(PostalCode::get()->map('ID','Suburb'))
->setEmptyString('--Please Select--')),
FieldList::create(
FormAction::create("AddCustomer","Add customer")
->setStyle("success")
),
RequiredFields::create(array("Name","Surname","Tel1", "Address", ))
)
->setLayout("horizontal");
}
// ADD CUSTOMER TO DATABASE
public static function AddCustomer($data, $form) {
$submission = new Customer();
$form->saveInto($submission);
$submission->write();
Controller::curr()->redirectBack();
}
}
--------------------------------------------------------------------------
i have updated my page.ss template with $CustomerForm but when i go to
www.mysite/customer...... nothing renders? Any ideas?