Friday, July 6, 2012

Re: The new Hash class and complex find statements.

Hash::extract('{n}.Content[type=/Article/]', $items);

I think :)


On 06/07/12 10:19, Stefano Zoffoli wrote:
Hi,

i'll start with an example. This is my array:

$items = array(
0 => array(
'Content'  => array(
'id'  => '1',
...
'type'  => 'Article',
...
),
'User'   => array(
...
),
),
1 => array(
'Content'  => array(
'id'  => '2',
...
'type'  => 'Page',
...
),
'User'   => array(
...
),
),
2 => array(
'Content'  => array(
'id'  => '3',
...
'type'  => 'Article',
...
),
'User'   => array(
...
),
),
);

With the old Set class i could use xpath syntax to filter by content type like this:

$results = Set::extract('/Content[type=Article]/..', $children);

And it gave me this array:

$results = array(
0 => array(
'Content'  => array(
'id'  => '1',
...
'type'  => 'Article',
...
),
'User'   => array(
...
),
),
1 => array(
'Content'  => array(
'id'  => '3',
...
'type'  => 'Article',
...
),
'User'   => array(
...
),
),
);

I tried to convert that function call with the new Hash class, but i failed.
I tried:

Hash::extract('{n}.Content[type=Article]', $items);
Hash::extract('{n}.Content[type=Article]..', $items);
Hash::extract('{n}[Content.type=Article]', $items);
Hash::extract('{n}[type=Article]', $items);
Hash::extract('{n}.[Content.type=Article]', $items);
Hash::extract('{n}.[type=Article]', $items);

and the same with quoted condition ([type="Article"]).

How can I do to have the same results as before?

--
Dott. Stefano Zoffoli
Web Development & Internet Technologies

Librasoft Snc
http://www.librasoftsnc.it
Via della Luna, 13
47034 Forlimpopoli (FC)
Tel. +39 0543 424612
Fax +39 0543 424612
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


No comments: