Re: R: Format ID field throughout

2007-03-22 Thread Mike Digital Egg

OK, thanks Sam, sounds like a good idea, I will give it a try.

Cheers

Mike

On Mar 18, 4:48 pm, "Samuel DeVore" <[EMAIL PROTECTED]> wrote:
> you could have the after find create a format_id field on the fly and
> then you would still have the id field for linking and other work.
> Then you can use the format_id for display and the id for the 'work'
>
> Sam D
>
> On 3/18/07, Mike Digital Egg <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Thanks for the tip, I have tried that and it worked. However I have
> > now run into a new problem which is that the code now breaks the
> > links.
>
> > For example:
>
> > The URL to edit a project is now: /projects/edit/FWL0001 which
> > doesn''t work.
>
> > I guess I need to reverse the transformation on any database queries,
> > the logical place for this seems to be in beforeFind, but I can't seem
> > to work out how to change the ID field back tot it's original number.
>
> > Anyone got any ideas, or should I just give up on this method?
>
> > Cheers
>
> > Mike
>
> > On Mar 17, 11:36 pm, "Marco \(GMail\)" <[EMAIL PROTECTED]> wrote:
> > >  All ok  but you must return $results ;-)
> > >  function afterFind($results) {
> > >   foreach ($results as $result_id => $result) {
> > > $results[$result_id]['Model']['id'] = 'FLW' . $result['Model'] ['id'];
> > >   }
> > >   return $results; // <<
>
> > > }
>
> > > -Messaggio originale-
> > > Da: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] Per conto
> > > di djiize
> > > Inviato: sabato 17 marzo 2007 19.35
> > > A: Cake PHP
> > > Oggetto: Re: Format ID field throughout
>
> > > try to play with the Model's function afterFind
>
> > > A quick try, in your model:
> > > function afterFind($results) {
> > >   foreach ($results as $result_id => $result) {
> > > $results[$result_id]['Model']['id'] = 'FLW' . $result['Model'] ['id'];
> > >   }
>
> > > }
>
> > > On 17 mar, 13:30, "Mike Digital Egg" <[EMAIL PROTECTED]> wrote:
>
> > > > Hi,
>
> > > > I am looking for the best way to format an ID field every time it
> > > > appears, without having to specifcally tell it to. Let me explain a
> > > > bit further:
>
> > > > I have a table called Projects, each project has an ID (numeric auto
> > > > increment) so a typical output from a db call would be:
>
> > > > ID, Project Name, Owner, Created
> > > > 1,My Project,Mike,14/03/2007
> > > > 2,My Second Project,Nigel,16/03/2007
>
> > > > Idealy I would like to transform the ID field output to something
> > > > like:
>
> > > > FWL0001
> > > > FWL0002
>
> > > > I know this can be done easily in the view, but what if I could make
> > > > the model output the ID in this format every time.
>
> > > > I think this is possible in RoR but I'm not sure how to do it in Cake,
> > > > is this what the 'behaviors' folder is for in the model folder?
>
> > > > Any help would be appreciated.
>
> > > > Cheers
>
> > > > Mike
>
> --
> (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/


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: R: Format ID field throughout

2007-03-18 Thread Samuel DeVore

you could have the after find create a format_id field on the fly and
then you would still have the id field for linking and other work.
Then you can use the format_id for display and the id for the 'work'

Sam D

On 3/18/07, Mike Digital Egg <[EMAIL PROTECTED]> wrote:
>
> Thanks for the tip, I have tried that and it worked. However I have
> now run into a new problem which is that the code now breaks the
> links.
>
> For example:
>
> The URL to edit a project is now: /projects/edit/FWL0001 which
> doesn''t work.
>
> I guess I need to reverse the transformation on any database queries,
> the logical place for this seems to be in beforeFind, but I can't seem
> to work out how to change the ID field back tot it's original number.
>
> Anyone got any ideas, or should I just give up on this method?
>
> Cheers
>
> Mike
>
>
>
> On Mar 17, 11:36 pm, "Marco \(GMail\)" <[EMAIL PROTECTED]> wrote:
> >  All ok  but you must return $results ;-)
> >  function afterFind($results) {
> >   foreach ($results as $result_id => $result) {
> > $results[$result_id]['Model']['id'] = 'FLW' . $result['Model'] ['id'];
> >   }
> >   return $results; // <<
> >
> > }
> >
> > -Messaggio originale-
> > Da: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] Per conto
> > di djiize
> > Inviato: sabato 17 marzo 2007 19.35
> > A: Cake PHP
> > Oggetto: Re: Format ID field throughout
> >
> > try to play with the Model's function afterFind
> >
> > A quick try, in your model:
> > function afterFind($results) {
> >   foreach ($results as $result_id => $result) {
> > $results[$result_id]['Model']['id'] = 'FLW' . $result['Model'] ['id'];
> >   }
> >
> > }
> >
> > On 17 mar, 13:30, "Mike Digital Egg" <[EMAIL PROTECTED]> wrote:
> >
> > > Hi,
> >
> > > I am looking for the best way to format an ID field every time it
> > > appears, without having to specifcally tell it to. Let me explain a
> > > bit further:
> >
> > > I have a table called Projects, each project has an ID (numeric auto
> > > increment) so a typical output from a db call would be:
> >
> > > ID, Project Name, Owner, Created
> > > 1,My Project,Mike,14/03/2007
> > > 2,My Second Project,Nigel,16/03/2007
> >
> > > Idealy I would like to transform the ID field output to something
> > > like:
> >
> > > FWL0001
> > > FWL0002
> >
> > > I know this can be done easily in the view, but what if I could make
> > > the model output the ID in this format every time.
> >
> > > I think this is possible in RoR but I'm not sure how to do it in Cake,
> > > is this what the 'behaviors' folder is for in the model folder?
> >
> > > Any help would be appreciated.
> >
> > > Cheers
> >
> > > Mike
>
>
> >
>


-- 
(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/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: R: Format ID field throughout

2007-03-18 Thread Mike Digital Egg

Thanks for the tip, I have tried that and it worked. However I have
now run into a new problem which is that the code now breaks the
links.

For example:

The URL to edit a project is now: /projects/edit/FWL0001 which
doesn''t work.

I guess I need to reverse the transformation on any database queries,
the logical place for this seems to be in beforeFind, but I can't seem
to work out how to change the ID field back tot it's original number.

Anyone got any ideas, or should I just give up on this method?

Cheers

Mike



On Mar 17, 11:36 pm, "Marco \(GMail\)" <[EMAIL PROTECTED]> wrote:
>  All ok  but you must return $results ;-)
>  function afterFind($results) {
>   foreach ($results as $result_id => $result) {
> $results[$result_id]['Model']['id'] = 'FLW' . $result['Model'] ['id'];
>   }
>   return $results; // <<
>
> }
>
> -Messaggio originale-
> Da: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] Per conto
> di djiize
> Inviato: sabato 17 marzo 2007 19.35
> A: Cake PHP
> Oggetto: Re: Format ID field throughout
>
> try to play with the Model's function afterFind
>
> A quick try, in your model:
> function afterFind($results) {
>   foreach ($results as $result_id => $result) {
> $results[$result_id]['Model']['id'] = 'FLW' . $result['Model'] ['id'];
>   }
>
> }
>
> On 17 mar, 13:30, "Mike Digital Egg" <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I am looking for the best way to format an ID field every time it
> > appears, without having to specifcally tell it to. Let me explain a
> > bit further:
>
> > I have a table called Projects, each project has an ID (numeric auto
> > increment) so a typical output from a db call would be:
>
> > ID, Project Name, Owner, Created
> > 1,My Project,Mike,14/03/2007
> > 2,My Second Project,Nigel,16/03/2007
>
> > Idealy I would like to transform the ID field output to something
> > like:
>
> > FWL0001
> > FWL0002
>
> > I know this can be done easily in the view, but what if I could make
> > the model output the ID in this format every time.
>
> > I think this is possible in RoR but I'm not sure how to do it in Cake,
> > is this what the 'behaviors' folder is for in the model folder?
>
> > Any help would be appreciated.
>
> > Cheers
>
> > Mike


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



R: Format ID field throughout

2007-03-17 Thread Marco \(GMail\)

 All ok  but you must return $results ;-)
 function afterFind($results) {
  foreach ($results as $result_id => $result) {
$results[$result_id]['Model']['id'] = 'FLW' . $result['Model'] ['id'];
  }
  return $results; // <<
}

-Messaggio originale-
Da: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] Per conto
di djiize
Inviato: sabato 17 marzo 2007 19.35
A: Cake PHP
Oggetto: Re: Format ID field throughout


try to play with the Model's function afterFind

A quick try, in your model:
function afterFind($results) {
  foreach ($results as $result_id => $result) {
$results[$result_id]['Model']['id'] = 'FLW' . $result['Model'] ['id'];
  }
}

On 17 mar, 13:30, "Mike Digital Egg" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am looking for the best way to format an ID field every time it 
> appears, without having to specifcally tell it to. Let me explain a 
> bit further:
>
> I have a table called Projects, each project has an ID (numeric auto
> increment) so a typical output from a db call would be:
>
> ID, Project Name, Owner, Created
> 1,My Project,Mike,14/03/2007
> 2,My Second Project,Nigel,16/03/2007
>
> Idealy I would like to transform the ID field output to something
> like:
>
> FWL0001
> FWL0002
>
> I know this can be done easily in the view, but what if I could make 
> the model output the ID in this format every time.
>
> I think this is possible in RoR but I'm not sure how to do it in Cake, 
> is this what the 'behaviors' folder is for in the model folder?
>
> Any help would be appreciated.
>
> Cheers
>
> Mike




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---