addField()

addField($name, $column, $type, $length, array $options)

This method creates a field into the model mapping info
It can be called anytime anywhere by the Map Object

@param String $name
@param String $column
@param String $type
@param String $lenght
@param Array $options
@return PhpBURN_Map

Params


$name
The name or alias for your field in your database table that will used along the application ( do not need to be the same name from the database column but we strongly recomment to be ).

$column
Corresponds to the column at your database table

$type
Corresponds the TYPE of data of your field ( INT, VARCHAR, BLOB, etc, can be any data type used by your choosen database ).

$lenght
Lenght of the field

$options
Array of options of the field it can be:

“auto_increment” => true/false
“null” => true/false
“not_null” => true/false
“default_value” => SOMETHING
“primary” => true

Remind that for example if the field isn’t primary you don’t need to put primary => false, just dont put the primary option ( it work for the others too ).

Others options will be supported in next versions

Explanation


So, now we map our database table with our model and let the magic ready to start.

You can add a field on-the-fly but we strongly recommend you to put all into the _mapping() magic method into your PhpBURN Model.

Default usage class Users extends PhpBURN_Core { public $_tablename = “users”; public $_package = “phpburn”; public $id_user; public $first_name; public $last_name; public $birthday; public $password; public $gender; public $created_at; public function _mapping() { $this->getMap()->addField(‘id_user’,’id_user’,’int’,10,array(‘primary’ => true, ‘auto_increment’ => true, ‘not_null’ => true)) ->addField(‘first_name’,’first_name’,’varchar’,255,array(‘not_null’ => true)) ->addField(‘last_name’,’last_name’,’varchar’,255,array(‘not_null’ => true)) ->addField(‘birthday’,’birthday’,’datetime’,null,array()) ->addField(‘password’,’password’,’varchar’,255,array(‘not_null’ => true)) ->addField(‘gender’,’gender’,’enum’,’male,female’,array(‘not_null’ => true, ‘default_value’ => ‘male’ )) ->addField(‘created_at’,’created_at’,’datetime’,255,array(‘not_null’ => true)); } }

Well, this is it… you’re ready to rock ( or in this case to CRUD 😛 )