mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
adjusting the changes and adding some docs
This commit is contained in:
parent
00abe27ef8
commit
83a11b7189
1 changed files with 26 additions and 24 deletions
|
@ -2678,39 +2678,42 @@ class Model extends Object implements CakeEventListener {
|
|||
* @link http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
|
||||
*/
|
||||
public function find($type = 'first', $query = array()) {
|
||||
$query = $this->_beforeFind($type, $query);
|
||||
$this->findQueryType = $type;
|
||||
$this->id = $this->getID();
|
||||
|
||||
$query = $this->buildQuery($type, $query);
|
||||
if (is_null($query)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->_afterFind($type, $query);
|
||||
return $this->_readDataSource($type, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Before running a find
|
||||
* Read from the datasource
|
||||
*
|
||||
* Model::_readDataSource() is used by all find() calls to read from the data source and can be overloaded to allow
|
||||
* caching of datasource calls.
|
||||
*
|
||||
* @param string $type the find type to run
|
||||
* @param array $query the finds query params
|
||||
* {{{
|
||||
* protected function _readDataSource($type, $query) {
|
||||
* $cacheName = md5(json_encode($query));
|
||||
* $cache = Cache::read($cacheName, 'cache-config-name');
|
||||
* if ($cache !== false) {
|
||||
* return $cache;
|
||||
* }
|
||||
*
|
||||
* $results = parent::_readDataSource($type, $query);
|
||||
* Cache::write($cacheName, $results, 'cache-config-name');
|
||||
* return $results;
|
||||
* }
|
||||
* }}}
|
||||
*
|
||||
* @return array|null
|
||||
* @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
|
||||
* @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
|
||||
* @return array
|
||||
*/
|
||||
protected function _beforeFind($type, $query) {
|
||||
$this->findQueryType = $type;
|
||||
$this->id = $this->getID();
|
||||
|
||||
return $this->buildQuery($type, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* After running a find
|
||||
*
|
||||
* @param string $type the find type to run
|
||||
* @param array $query the finds query params
|
||||
* @param array $results they results from the find
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function _afterFind($type, $query) {
|
||||
protected function _readDataSource($type, $query) {
|
||||
$results = $this->getDataSource()->read($this, $query);
|
||||
$this->resetAssociations();
|
||||
|
||||
|
@ -2727,7 +2730,6 @@ class Model extends Object implements CakeEventListener {
|
|||
if ($this->findMethods[$type] === true) {
|
||||
return $this->{'_find' . ucfirst($type)}('after', $query, $results);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue