To save in your model using CakePHP you only have to supply that data to a specific model using the save() method.
The data needs to be in the following form:

PHP:
  1. (
  2.     [ModelName] => Array
  3.         (
  4.             [yourfieldname] => 'value'
  5.             [anotherfieldname] => 'value'
  6.         )
  7. )

To post data in this form to a controller for example is very easy using HTML helpers that are implemented in Cake. Everything we need to care about is that form elements are looking like: data[Modelname][fieldname] .

For example to acces a certain variable in a controller we will use;

PHP:
  1. $name_var = $this->data[‘Modelname’][‘formvariable’];

The input form in the view will look something like this:

PHP:
  1. $html->input('Modelname/formvariable')

In a form construction using helpers is best to respect the model structure using to give names to form elements the same names like fields we want to fill in the database.
Using this convention data sent from forms will be formatted automatically and will look putted in $this->data within you controller, so saving data becomes very easy.

Example of saving data:

PHP:
  1. function add() // action add
  2.     {
  3.         if (!empty($this->data))   // checking to see if $this->data is not empty
  4.         {
  5.             if ($this->Car->save($this->data)) // is data is saved returns true
  6.             {
  7.                 $this->flash('Your post has been saved.','/posts'); //displaying message with link
  8.             }
  9.         }
  10.     }

In the example above we are saving data in the Car model.
If you want to validate your data you can easily do this using your model.
Example:

PHP:
  1. class Car extends AppModel
  2. {
  3.     var $name = Car';
  4.     var $validate = array(
  5.         'name'  => VALID_NOT_EMPTY,
  6.         'model'   => VALID_NOT_EMPTY
  7.         'year'   => VALID_NOT_EMPTY
  8.    );
  9. }

Cake will check variables: name, model and year not to be empty.
In on of the next posts I will describe how easy is to save data in multiple related models.