Cakephp Classroom image

osdyui
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84|Last
Lessons:-Models

Additional Methods and Properties
While CakePHP’s model functions should get you where you need to go, don’t forget that model classes are
just that: classes that allow you to write your own methods or define your own properties.
Any operation that handles the saving and fetching of data is best housed in your model classes. This concept
is often referred to as the fat model.
class Example extends AppModel {
public function getRecent() {
$conditions = array(
’created BETWEEN (curdate() - interval 7 day) and (curdate() - interval 0 day))’
);
return $this->find(’all’, compact(’conditions’));
}
}
This getRecent() method can now be used within the controller.
$recent = $this->Example->getRecent();
Model::associations()
Get associations:
$result = $this->Example->associations();
// $result equals array(’belongsTo’, ’hasOne’, ’hasMany’, ’hasAndBelongsToMany’)
Model::buildQuery(string $type = ’first’, array $query = array())
Builds the query array that is used by the data source to generate the query to fetch the data.
Model::deconstruct(string $field, mixed $data)
Deconstructs a complex data type (array or object) into a single field value.
Model::escapeField(string $field = null, string $alias = null)
Escapes the field name and prepends the model name. Escaping is done according to the current database
driver’s rules.
Model::exists($id)
Returns true if a record with the particular ID exists.
If ID is not provided it calls Model::getID() to obtain the current record ID to verify, and then performs
a Model::find(’count’) on the currently configured datasource to ascertain the existence of the
record in persistent storage.

 
 
 

osdyui

Skills    Cakephp

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)