Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP - Set Default Field Values in the Model

Tags:

cakephp

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
    ),
);  
like image 740
freshest Avatar asked Dec 01 '11 15:12

freshest


People also ask

Why we used this -> set () in CakePHP?

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.

What is CakePHP model?

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.


1 Answers

you should always try to set default values from the controller: http://www.dereuromark.de/tag/default-values/

like image 172
mark Avatar answered Nov 09 '22 10:11

mark