Wednesday, November 3, 2010

Model: User

Models provide the interface to the database. While the tables they refer to are named plurally, the models are named singularly.

Create /app/models/user.php
<?php
class User extends AppModel {
    var $name = 'User';
}
?>
If the primary key field of your table is not "id" then you need to add the variable $primaryKey, otherwise you can leave it out.
    var $primaryKey = 'unique_id';
If you didn't design your tables around CakePHP (why wouldn't you?) then you can explicitly specify the table name for your model here as well.
    var $useTable = 'table_name';
If you don't want a model to use a table, such as for display purposes only, or when pulling data from an external source, you can set the useTable variable to false.
    var $useTable = false;
Once you do that, you can set the schema for the non-table data with the _schema variable.
    var $_schema = array(
        'last_name' => array('type' => 'strong', 'length' => 50),
        'date_of_birth' => array('type' => 'date')
    );
Upload the file.

No comments:

Post a Comment