Cakephp Classroom image

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

));
// ...
}
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(’list’) will be in the following form:
Array
(
//[id] => ’displayValue’,
[1] => ’displayValue1’,
[2] => ’displayValue2’,
[4] => ’displayValue4’,
[5] => ’displayValue5’,
[6] => ’displayValue6’,
[3] => ’displayValue3’,
)
When calling find(’list’) the fields passed are used to determine what should be used as the array
key, value and optionally what to group the results by. By default the primary key for the model is used for
the key, and the display field (which can be configured using the model attribute displayField) is used for
the value. Some further examples to clarify:
public function some_function() {
// ...
$justusernames = $this->Article->User->find(’list’, array(
’fields’ => array(’User.username’)
));
$usernameMap = $this->Article->User->find(’list’, array(
’fields’ => array(’User.username’, ’User.first_name’)
));
$usernameGroups = $this->Article->User->find(’list’, array(
’fields’ => array(’User.username’, ’User.first_name’, ’User.group’)
));
// ...
}
With the above code example, the resultant vars would look something like this:
$justusernames = Array
(
//[id] => ’username’,
[213] => ’AD7six’,
[25] => ’_psychic_’,
[1] => ’PHPNut’,
[2] => ’gwoo’,
[400] => ’jperras’,
)
$usernameMap = Array(
//[username] => ’firstname’,
[’AD7six’] => ’Andy’,
[’_psychic_’] => ’John’,
[’PHPNut’] => ’Larry’,
[’gwoo’] => ’Gwoo’,
[’jperras’] => ’Joël’,
)
$usernameGroups = Array
(
[’User’] => Array
(
[’PHPNut’] => ’Larry’,
[’gwoo’] => ’Gwoo’,
)
[’Admin’] => Array
(
[’_psychic_’] => ’John’,
[’AD7six’] => ’Andy’,
[’jperras’] => ’Joël’,
)
)
find(‘threaded’)
find(’threaded’, $params) returns a nested array, and is appropriate if you want to use the
parent_id field of your model data to build nested results. Below are a couple of simple (controller
code) examples:
public function some_function() {
// ...
$allCategories = $this->Category->find(’threaded’);
$comments = $this->Comment->find(’threaded’, array(
’conditions’ => array(’article_id’ => 50)
));
// ...
}
Tip: A better way to deal with nested data is using the Tree behavior
In the above code example, $allCategories will contain a nested array representing the whole category
structure. The results of a call to find(’threaded’) will be of the following form:
Array
(
[0] => Array
(

 
 
 

pankaj

Skills    Cakephp

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

  Students (0)