Wednesday, May 4, 2011

Re: Set::extract on an array containing one element

Really?

I was doing an extract on a previous combine which put the ID as the
numeric key.
But, switching it with a 0 and now everything seems to work.

Still, it's strange that when I add another element with random key,
it's now working.

Anyway, I'll find an alternative for my ids.

Thanks for the reply.

On 4 mai, 08:01, "Dr. Loboto" <drlob...@gmail.com> wrote:
> Set::extract("/Some/thing", $data) assumes that you have true list -
> array with numeric keys 0, 1, 2, ... - but not an associative array
> with keys "some", "thing", ... or 4, 2, 15, ...
>
> If you call it as Set::extract("/Some/thing", array_values($data))
> when $data is associative array it will pass.
>
> On 3 май, 16:21, Gluckens <danny30...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Of course I know how to do it whithout the extract method.
>
> > The point is, if the extract is not always working, it's not really
> > usable cause you never know when it will break your things
>
> > Someone points me to this ticket which could be relatedhttp://cakephp.lighthouseapp.com/projects/42648/tickets/104-testpatch...
>
> > But anyway, this fix would probably not be coming soon
>
> > Seems like I'll need to rewrite large parts of code... ugh
>
> > On 2 mai, 19:51, Otavio Martins Salomao <otaviosalo...@gmail.com>
> > wrote:
>
> > > u try this!
> > > foreach($test as $element)
> > >      $result = $element['Deep1']['Deep2']['extract'];
>
> > > 2011/5/2 Gluckens <danny30...@gmail.com>
>
> > > > Hi everyone,
>
> > > > I'm trying to extract data from an array containing only one element
> > > > and it doesn't seem to work properly.
> > > > Here's an example :
>
> > > > Starting array
> > > > $test = array(4 => array('Deep1' => array('data1' => 'nothing',
> > > > 'Deep2' => array('extract' => 1))));
> > > > Array
> > > > (
> > > >    [4] => Array
> > > >        (
> > > >            [Deep1] => Array
> > > >                (
> > > >                    [data1] => nothing
> > > >                    [Deep2] => Array
> > > >                        (
> > > >                            [extract] => 1
> > > >                        )
> > > >                )
> > > >        )
> > > > )
>
> > > > Set::extract('/Deep1/Deep2[extract=1]', $test);
> > > > NOT CORRECT
> > > > Array
> > > > (
> > > > )
>
> > > > But, when I add another element, let's say
> > > > $test[12] = array();
> > > > It works fine
> > > > Set::extract('/Deep1/Deep2[extract=1]', $test);
> > > > CORRECT
> > > > Array
> > > > (
> > > >    [0] => Array
> > > >        (
> > > >            [Deep2] => Array
> > > >                (
> > > >                    [extract] => 1
> > > >                )
> > > >        )
> > > > )
>
> > > > Am I using it properly?
> > > > Thanks in advance for any help.
>
> > > > --
> > > > Our newest site for the community: CakePHP Video Tutorials
> > > >http://tv.cakephp.org
> > > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp
> > > > 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
> > > > athttp://groups.google.com/group/cake-php

--
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: