天天看点

CakePHP 1.2RC2 手册学习笔记

1.Titles

    An object, in the physical sense, often has a name or a title in which to refer to it by. A person has a name like John or Mac or Buddy. A blog post has a title. A category has a name.

    By specifying a title or name field, CakePHP will automatically use this label in various circumstances:

        * Scaffolding — page titles, fieldset labels

        * Lists — normally used for <select> drop-downs

        * TreeBehavior — reordering, tree views

    If you have a title and name field in your table, the title will be used.

=========================

2.created and modified

=========================

3.hasOne

    *   className: the classname of the model being associated to the current model. If you’re defining a ‘User hasOne Profile’ relationship, the className key should equal ‘Profile.’

    * foreignKey: the name of the foreign key found in the other model. This is especially handy if you need to define multiple hasOne relationships. The default value for this key is the underscored, singular name of the current model, suffixed with ‘_id’. In the example above it would default to 'user_id'.

    * conditions: An SQL fragment used filter related model records. It’s good practice to use model names in SQL fragments: “Profile.approved = 1” is always better than just “approved = 1.”

    * fields: A list of fields to be retrieved when the associated model data is fetched. Returns all fields by default.

    * dependent: When the dependent key is set to true, and the model’s delete() method is called with the cascade parameter set to true, associated model records are also deleted. In this case we set it true so that deleting a User will also delete her associated Profile.

=========================

4. belongsTo

    *   className: the classname of the model being associated to the current model. If you’re defining a ‘Profile belongsTo User’ relationship, the className key should equal ‘User.’

    * foreignKey: the name of the foreign key found in the current model. This is especially handy if you need to define multiple belongsTo relationships. The default value for this key is the underscored, singular name of the other model, suffixed with ‘_id’.

    * conditions: An SQL fragment used filter related model records. It’s good practice to use model names in SQL fragments: “User.active = 1” is always better than just “active = 1.”

    * fields: A list of fields to be retrieved when the associated model data is fetched. Returns all fields by default.

    * counterCache: (bool) If set to true the associated Model will automatically increase or decrease the “[singular_model_name]_count” field in the foreign table whenever you do a save() or delete(). The value in the counter field represents the numer of related rows.

=========================

5.hasMany

    *   className: the classname of the model being associated to the current model. If you’re defining a ‘User hasMany Comment’ relationship, the className key should equal ‘Comment.’

    * foreignKey: the name of the foreign key found in the other model. This is especially handy if you need to define multiple hasMany relationships. The default value for this key is the underscored, singular name of the other model, suffixed with ‘_id’.

    * conditions: An SQL fragment used filter related model records. It’s good practice to use model names in SQL fragments: “Comment.status = 1” is always better than just “status = 1.”

    * fields: A list of fields to be retrieved when the associated model data is fetched. Returns all fields by default.

    * order: An SQL fragment that defines the sorting order for the returned associated rows.

    * limit: The maximum number of associated rows you want returned.

    * offset: The number of associated rows to skip over (given the current conditions and order) before fetching and associating.

    * dependent: When dependent is set to true, recursive model deletion is possible. In this example, Comment records will be deleted when their associated User record has been deleted.

    * Note: the second parameter of the Model->delete() method must be set to true in order for recursive deletion to occur.

    * finderQuery: A complete SQL query CakePHP can use to fetch associated model records. This should be used in situations that require very custom results.

=========================

6.hasAndBelongsToMany

    *   className: the classname of the model being associated to the current model. If you’re defining a ‘User hasMany Comment’ relationship, the className key should equal ‘Comment.’

    * joinTable: The name of the join table used in this association (if the current table doesn’t adhere to the naming convention for HABTM join tables).

    * foreignKey: the name of the foreign key found in the other model. This is especially handy if you need to define multiple HABTM relationships. The default value for this key is the underscored, singular name of the other model, suffixed with ‘_id’.

    * associationForeignKey: the name of the foreign key found in the current model. This is especially handy if you need to define multiple HABTM relationships. The default value for this key is the underscored, singular name of the current model, suffixed with ‘_id’.

    * conditions: An SQL fragment used filter related model records. It’s good practice to use model names in SQL fragments: “Comment.status = 1” is always better than just “status = 1.”

    * fields: A list of fields to be retrieved when the associated model data is fetched. Returns all fields by default.

    * order: An SQL fragment that defines the sorting order for the returned associated rows.

    * limit: The maximum number of associated rows you want returned.

    * offset: The number of associated rows to skip over (given the current conditions and order) before fetching and associating.

    * finderQuery, deleteQuery, insertQuery: A complete SQL query CakePHP can use to fetch, delete, or create new associated model records. This should be used in situations that require very custom results.

=========================

7.find

   1).  find(string $conditions, array $fields, string $order, int $recursive);

   2).  find($type, $params);

   $type is either 'all', 'list', 'first', or 'count'. First is the default find type.

   $params is an array with any of the following available options as keys:

array(
          'conditions' => array('Model.field' => $thisValue), //array of conditions
          'recursive' => 1, //int
          'fields' => array('Model.field1', 'Model.field2'), //array of field names
          'order' => 'Model.created', //string or array defining order
          'limit' => n, //int
          'page' => n //int
      )          

=========================

8.recursive

    Depth    Description

    -1    Cake fetches Group data only, no joins.

    0      Cake fetches Group data and its domain

    1      Cake fetches a Group, its domain and its associated Users

    2      Cake fetches a Group, its domain, its associated Users, and the Users' associated Articles

=========================

9.Changing Encryption Type
Security::setHash('md5'); // or sha1 or sha256.