Cakephp Classroom image

osdyui
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19|Last
Lessons:-Models

[field2] => value2
[field3] => value3
)
[AssociatedModelName] => Array
(
[id] => 1
[field1] => value1
[field2] => value2
[field3] => value3
)
)
find(‘count’)
find(’count’, $params) returns an integer value. Below are a couple of simple (controller code)
examples:
public function some_function() {
// ...
$total = $this->Article->find(’count’);
$pending = $this->Article->find(’count’, array(
’conditions’ => array(’Article.status’ => ’pending’)
));
$authors = $this->Article->User->find(’count’);
$publishedAuthors = $this->Article->find(’count’, array(
’fields’ => ’DISTINCT Article.user_id’,
’conditions’ => array(’Article.status !=’ => ’pending’)
));
// ...
}
Note: Don’t pass fields as an array to find(’count’). You would only need to specify fields for a
DISTINCT count (since otherwise, the count is always the same - dictated by the conditions).
find(‘all’)
find(’all’, $params) returns an array of (potentially multiple) results. It is in fact the mechanism
used by all find() variants, as well as paginate. Below are a couple of simple (controller code)
examples:
public function some_function() {
// ...
$allArticles = $this->Article->find(’all’);
$pending = $this->Article->find(’all’, array(
’conditions’ => array(’Article.status’ => ’pending’)
));
$allAuthors = $this->Article->User->find(’all’);$allPublishedAuthors = $this->Article->User->find(’all’, array(
’conditions’ => array(’Article.status !=’ => ’pending’)
));
// ...
}
Note: In the above example $allAuthors will contain every user in the users table. There will be no
condition applied to the find as none were passed.
The results of a call to find(’all’) will be of the following form:
Array
(
[0] => Array
(
[ModelName] => Array
(
[id] => 83
[field1] => value1
[field2] => value2
[field3] => value3
)
[AssociatedModelName] => Array
(
[id] => 1
[field1] => value1
[field2] => value2
[field3] => value3
)
)
)
find(‘list’)
find(’list’, $params) returns an indexed array, useful for any place where you would want a list
such as for populating input select boxes. Below are a couple of simple (controller code) examples:
public function some_function() {
// ...
$allArticles = $this->Article->find(’list’);
$pending = $this->Article->find(’list’, array(
’conditions’ => array(’Article.status’ => ’pending’)
));
$allAuthors = $this->Article->User->find(’list’);
$allPublishedAuthors = $this->Article->find(’list’, array(
’fields’ => array(’User.id’, ’User.name’),
’conditions’ => array(’Article.status !=’ => ’pending’),
’recursive’ => 0

 
 
 

osdyui

Skills    Cakephp

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

  Students (0)