How do you set a default value for a field in a model?
EDIT:
I have tried the method using _schema as suggested, but the default value is not being used.
public $_schema = array(
'newsletter' => array(
'default' => 1
),
);
Controller actions generally use Controller::set() to create a context that View uses to render the view layer. Because of the conventions that CakePHP uses, you don't need to create and render the view manually. Instead, once a controller action has completed, CakePHP will handle rendering and delivering the View.
Usually, model classes represent data and are used in CakePHP applications for data access. They generally represent a database table but can be used to access anything that manipulates data such as files, external web services, or iCal events. A model can be associated with other models.
you should always try to set default values from the controller: http://www.dereuromark.de/tag/default-values/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With