I know that set:extract can get one i开发者_如何转开发tem from an array like this
Set::extract('/myArray/item',$items);
but what if I need multiple items? with id, i need name too.
You should be able to get multiple items using Set::extract
but it depends on the structure of your array and what you want to extract from that array.
For example let's say we have something like...
- [Fruits]
- [Apples]
- [Washington]
- [Sour]
- [Oranges]
- [Grapes]
- [Apples]
To select all children of fruit you'd enter Fruit
. To get specific types of Apples you'd do /Fruits/Apple
. There are a lot of other things that you can do as well. Go to XPath Syntax for more information. Hope this helps.
Felix Geisendörfer from Debuggable has some really excellent examples of how to utilize Set::extract to get multiple values from various nested data structures
http://debuggable.com/posts/cake-12s-set-class-eats-arrays-for-breakfast:480f4dd6-d084-4fb7-bacc-49fdcbdd56cb
My 2 cents: Take a look at the sources ($CAKE_DIR/libs/set.php or online and in $CAKE_DIR/tests/cases/libs/set.test.php or online): you'll find some usage examples (this is true at least for cakephp 1.2.x).
精彩评论