domingo, 2 de diciembre de 2007

How to setup default form values in cakephp

If you want to configure some default values for the form you can use the model's create function this way:



//in you booking model
function create($data) {
if (empty($data['Booking']['country_id'])) {
$data['Booking']['country_id'] = 225;
}

parent::create($data);
}


this would preconfigure country_id value to 255

Update:
In order to have these data available in your view you must setup $this->data variable in your controller:


$this->data = $this->Booking->create();


you can also setup $this->data variable directly in your controller:

$this->data['Booking']['country_id'];


* if you are testing it with firefox be aware that the browser doesn't refresh your form data values until you press ctrl+f5

No hay comentarios: