Свежайшие Пирожки от CakePHP по-русски

Полнейшее руководство CakePHP 1.2 на русском языке, горячие новости и полезные статьи

extract

array Set::extract ($path, $data=null, $options=array())

Set::extract uses basic XPath 2.0 syntax to return subsets of your data from a find or a find all. This function allows you to retrieve your data quickly without having to loop through multi dimentional arrays or traverse through tree structures.

If $path is an array or $data is empty it the call is delegated to Set::classicExtract.

Простой текст
  1. // Common Usage:
  2. $users = $this->User->find("all");
  3. $results = Set::extract('/User/id', $users);
  4. // results returns:
  5. // array(1,2,3,4,5,...);

Currently implemented selectors:

Selector Note
/User/id similar to the classic {n}.User.id
/User[2]/name selects the name of the second User
/User[id<2] selects all Users with an id < 2
/User[id>2][<5] selects all Users with an id > 2 but < 5
/Post/Comment[author_name=john]/../name Selects the name of all Posts that have at least one Comment written by john
/Posts[title] Selects all Posts that have a 'title' key
/Comment/.[1] Selects the contents of the first comment
/Comment/.[:last] Selects the last comment
/Comment/.[:first] Selects the first comment
/Comment[text=/cakephp/i] Selects the all comments that have a text matching the regex /cakephp/i
/Comment/@* Selects the all key names of all comments

Currently, only absolute paths starting with a single '/' are supported. Please report any bugs as you find them, and suggestions for additional features are also welcome

To learn more about Set::extract() refer to function testExtract() in /cake/tests/cases/libs/set.test.php.