On Oct 8, 6:55 am, alberto <[email protected]> wrote:
> .....
>
> I want to sort by date, the date variable is contained into name_item1
> and name_item4 that are two different names
> so i tried to use this path {n}.{s}.date but doesn't work probably
> becouse there is name_item2 and name_item3 ???
You can also use regular expressions inside {}'s as well as {n} and
{s}. However, without consistent keys, it's not so easy. You would
think you would just be able to do: "{n}.{name_item[\d]+}.date", but
since Set::sort first performs a Set::extract on the data using the
path given, Set::extract will actually also include the "name_item2"
in the result even though it has no "date" key (but because it matched
the regular expression). This makes Set::sort not work.
So as far as I can see, the only way to sort the type of array you're
describing, you'd have to manually specify the numbered suffixes that
will contain "date" keys in your path, like: "{n}.{name_item(1|
4)}.date". Using that path, Set::sort will now correctly return the
array sorted by date as expected because the regular expression in the
path will no longer match "name_item2". You could also reverse the
regular expression to say all suffixes except certain numbers, if that
is a shorter list than the ones that will have "date" keys. An example
of a path in this form would be: "{n}.{name_item[^25]}.date", where
name_item2 and name_item5 should be excluded because they do not have
"date" keys.
You should also be able to use XPath-style expressions, since as
mentioned before, Set::sort directly passes its arguments to
Set::extract (which can use XPath or the classicExtract expressions).
However, I don't think the current implementation of XPath in the
Set::extract method is powerful enough to let you do what you are
needing to do.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---