Cakephp Classroom image

Anil  Bist / Professional / Web Technology

 
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.

 
 
 
image
Anil  Bist

Skills    Cakephp

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)