EXTREMELY NEAT!! (please excuse my excitement :D )

Just one thing in the complicated example....

'{n}.User.surname.0'  ???

Why the .0 at the end?
--
Baz L
Web Development 2.0
http://WebDevelopment2.com/

On Feb 11, 2008 11:10 AM, Samuel DeVore <[EMAIL PROTECTED]> wrote:

>
> grigri, can you write up some of this and send to John for the
> documentation project, this has got to get in there.
>
> Sam D
>
> On Feb 11, 2008 10:06 AM, grigri <[EMAIL PROTECTED]> wrote:
> >
> > It's easy, really - for each of the 3 fields (keyPath, valuePath and
> > groupPath), instead of passing a string, you can pass an array.
> >
> > The first entry in the array is the format string, the rest are the
> > parameters (extracted with Set::extract()).
> >
> > The format is exactly the same as sprintf() [it calls vsprintf()
> > internally].
> >
> > So, passing array('%s %s', '{n}.Person.firstname',
> > '{n}.Person.surname') as the valuePath does the following:
> >
> > * realizes it's an array, not a string
> > * grabs the first entry ('%s %s') for the format, remembers the rest
> > as parameters
> > * for each parameter, calls Set::extract($data, ...) :
> >     + Set::extract($data, '{n}.Person.firstname');
> >     + Set::extract($data, '{n}.Person.last');
> > * calls vsprintf($format, $parameters)
> >
> > You can also use "{1} {2}" as the format string instead of the
> > sprintf() format, if you like. Personally I prefer the sprintf format,
> > because I'm more used to it. Plus you can do things like padding,
> > truncating and whatnot:
> >
> > Slightly more complicated example:
> >
> > $data = array(
> >   array('User' => array('id' => 1, 'firstname' => 'Joe', 'surname' =>
> > 'Bloggs')),
> >   array('User' => array('id' => 2, 'firstname' => 'Fred', 'surname' =>
> > 'Bloggs')),
> >   array('User' => array('id' => 3, 'firstname' => 'Jim', 'surname' =>
> > 'Beam')),
> >   array('User' => array('id' => 4, 'firstname' => 'Jack', 'surname' =>
> > 'Daniels')),
> > );
> >
> > debug(Set::combine(
> >   $data,
> >   '{n}.User.id',
> >   array('%2$s, %1$.1s.', '{n}.User.firstname', '{n}.User.surname'),
> >   '{n}.User.surname.0'
> > ));
> >
> > result:
> > Array
> > (
> >     [B] => Array
> >         (
> >             [1] => Bloggs, J.
> >             [2] => Bloggs, F.
> >             [3] => Beam, J.
> >         )
> >
> >     [D] => Array
> >         (
> >             [4] => Daniels, J.
> >         )
> >
> > )
> >
> > neat, no?
> >
> >
> > On Feb 11, 4:36 pm, Baz <[EMAIL PROTECTED]> wrote:
> > > Yeah, I've seen that a lot.
> > >
> > > What I was referring to with grigri's example is that :
> > >
> > > array(%s %s %s) thing for the path...
> > >
> > > I have tons of examples like these where I need to do a "$firstname -
> > > $lastname" type of thing.
> > >
> > > On Feb 11, 2008 10:22 AM, Samuel DeVore <[EMAIL PROTECTED]> wrote:
> > >
> > >
> > >
> > > > there is the start of some information on Set:: at
> > >
> > > >
> http://www.thinkingphp.org/2007/02/24/cake-12s-set-class-eats-arrays-...
> > >
> > > > Sam D
> > >
> > > > On Feb 11, 2008 9:04 AM, Baz <[EMAIL PROTECTED]> wrote:
> > > > > Are you serious?????
> > >
> > > > > Ok, you guys need a Set::combine tutorial or something!
> > >
> > > > > I've been trying to figure this out how to combine fields for a
> few
> > > > months
> > > > > now. I've been reduced to creating a custom array in a foreach
> loop.
> > >
> > > > > But I knew, deep down inside, there must be way.  ThanX
> > > > > --
> > > > > Baz L
> > > > > Web Development 2.0
> > > > >http://WebDevelopment2.com/
> > >
> >
> > > > > On Feb 11, 2008 3:59 AM, roryy <[EMAIL PROTECTED]> wrote:
> > >
> > > > > > It works, thank you very much!
> > > > > > Now i'm gonna try to make a function to combine the two
> functions :)
> > >
> > > > > > On 11 feb, 10:41, grigri <[EMAIL PROTECTED]> wrote:
> > > > > > > find('list') only works with simple fields, you won't be able
> to do
> > > > > > > this.
> > >
> > > > > > > Still, it's easy enough with find('all') and Set::combine():
> > >
> > > > > > > $people = $this->Person->find('all', array(
> > > > > > >   'fields' => array('id', 'firstname', 'insertion',
> 'surname'),
> > > > > > >   'recursive' => -1
> > > > > > > ));
> > > > > > > $list = Set::combine(
> > > > > > >   $people,
> > > > > > >   '{n}.Person.id',
> > > > > > >   array('%s %s %s', '{n}.Person.firstname',
> '{n}.Person.insertion',
> > > > > > > '{n}.Person.surname')
> > > > > > > );
> > >
> > > > > > > On Feb 11, 9:25 am, roryy <[EMAIL PROTECTED]> wrote:
> > >
> > > > > > > > Hello cakephp friends,
> > >
> > > > > > > > I have 2 tables. Communications and people. In
> communications/add
> > > > i
> > > > > > > > want a list where you can choose one person from table
> people. But
> > > > you
> > > > > > > > don't see his name, only his ID. I have these fields in
> table
> > > > people:
> > >
> > > > > > > > id
> > > > > > > > firstname
> > > > > > > > insertion
> > > > > > > > surname
> > >
> > > > > > > > Can someone help me to make a list where you can see a
> persons
> > > > > > > > firstname, insertion and surname with find('list' , .....)
> in the
> > > > > > > > communication controller.
> > >
> > > > > > > > Thanks in advance!- Tekst uit oorspronkelijk bericht niet
> > > > weergeven -
> > >
> > > > > > > - Tekst uit oorspronkelijk bericht weergeven -
> > >
> > > > --
> > > > --
> > > > (the old fart) the advice is free, the lack of crankiness will cost
> you
> > >
> > > > - its a fine line between a real question and an idiot
> > >
> > > >
> http://blog.samdevore.com/archives/2007/03/05/when-open-source-bugs-me/
> > > >http://blog.samdevore.com/cakephp-pages/my-cake-wont-bake/
> > > >http://blog.samdevore.com/cakephp-pages/i-cant-bake/
> > >
> >
>
>
>
> --
> --
> (the old fart) the advice is free, the lack of crankiness will cost you
>
> - its a fine line between a real question and an idiot
>
> http://blog.samdevore.com/archives/2007/03/05/when-open-source-bugs-me/
> http://blog.samdevore.com/cakephp-pages/my-cake-wont-bake/
> http://blog.samdevore.com/cakephp-pages/i-cant-bake/
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to