Personally I dislike all the methods mentioned.

This is configuration data - load it from a config file. In your
bootstap.php do a Configure::load( 'forms' ); somewhere near the
bottom.

Then in /app/config/forms.php

put the configuration information for the select options.

$config[ 'Forms' ][ 'genderSelectOptions' ] = array( 'M' => 'Male',
'F' => 'Female' );

and load them in your views with
Configure::read( 'Forms.genderSelectOptions' ) when you need the
options loaded into the form helper.

http://book.cakephp.org/view/924/The-Configuration-Class

Another option - more robust than the method above and similar to the
Model options mentioned above is to use an ArrayDatasource and have a
Gender model that relates to the User (or whatever model has the need
to select a gender)

https://github.com/cakephp/datasources

On May 19, 4:50 am, Jeremy Burns | Class Outfit
<[email protected]> wrote:
> I think this is the best advice (I always advocate storing everything in the 
> database) but there might just be the odd exception.
>
> Jeremy Burns
> Class Outfit
>
> [email protected]http://www.classoutfit.com
>
> On 19 May 2011, at 12:39, djogo wrote:
>
>
>
>
>
>
>
> > I think it depends whether you store this value in the database or
> > not.
>
> > If you do, the right thing is to create a table and then accessing it
> > by a model. For a very good reason, in big projects you don't want to
> > lose time thinking "is it a table or a array within a controller? in
> > which controller is it?".
>
> > Also, if this value is used in the database, later you may want to
> > write a single query to retrieve this data, and run this query on the
> > console (or a backup script, e.g.) and suddenly you realized that that
> > tied you to cakephp.
>
> > If you think that's the best solution (to keep this data as an array),
> > the ideal solution (in my mind) would be to have a Model which access
> > this array instead of a database table. If you only need it for drop
> > boxes, maybe this:
>
> > app/models/gender.php
>
> > class Gender // extends nothing
> > {
> >  var $data = array( 'M' => 'Male', 'F' => 'Female' );
>
> >  function find($type,$opt=null)
> >  {
> >    if ( $type='list' ) return $data;
> >    throw new exception(" find('$type') in bogus model isn't supported
> > - maybe it's time to use a real table." );
> >  }
>
> > }
>
> > I know, it's ugly, but what's the upside of all this coding? All data
> > in accessible by models, and you didn't wrote a lot of database tables
> > that will never change.
>
> > I would love proper support of "virtual" models that access data on a
> > CSV, static array, etc.
>
> > dfcp
>
> > On 18 maio, 15:46, Jason Mitchell <[email protected]> wrote:
> >> I have in a controller an array containing data used on the view to 
> >> populate
> >> a drop down. I put it on the controller, so the array could be used by
> >> multiple views associated with that controller (create, edit). 
> >> Additionally,
> >> it means that if I do ever have to change it, I just have to change it once
> >> (yup, lazy).
>
> >> Because the data is relatively static, and is used in only isolated
> >> instances, it didn't seem to be worth the effort of creating a model for
> >> that data, and establishing a relationship between models. And, putting it
> >> on the controller, worked.
>
> >> Admittedly, I'm new to MVC, but this really doesn't seem to jive 
> >> definition.
> >> Am I doing something wrong?  If so, how would one but this on the model,
> >> short of some sort of association with another model?
>
> >> --
> >> J. Mitchell
>
> > --
> > Our newest site for the community: CakePHP Video 
> > Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help 
> > others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > [email protected] 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
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to