Re: display enum values in dropdown

2006-09-18 Thread [EMAIL PROTECTED]

Thanks to everyone who replied, I didn't check this thread all weekend.


Nate: Thanks I moved the app model to model/app_model.php and updated
it with the it works great now. I've also updated the code that
retrieves the DB table name, cheers for that.

my 2p's worth: I think Enums are great, a good way to reduce complexity
of the database, even if they are a MySQL only thing : )


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



Re: display enum values in dropdown

2006-09-15 Thread [EMAIL PROTECTED]

To be honest, I don't think either are great solutions, because:

- if we put the code in our data model, then only that model can access
that function, we'd have to duplicate the code for other models that
might want to use an enum field.

- that snippet doesnt work with tables with underscores, to remedy that
you can $this-table
rather than doing this...
$tableName = strtolower(Inflector::pluralize($this-name));
Also if I create my own AppModel with the getEnumValues method in, that
resides in my app/models directory, I get errors. It only works when I
add the method to the cake/app_model.php class.

Anyway, it would be nice to get this updated in Cake, its a bit
inconsistent to have the functionality in the scaffolding but not
available in the model functionality. Is it just a case of submitting a
new ticket on the trac repository to get it looked at?

Cheers

James


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



Re: display enum values in dropdown

2006-09-15 Thread nate


[EMAIL PROTECTED] wrote:
 To be honest, I don't think either are great solutions, because:

 - if we put the code in our data model, then only that model can access
 that function, we'd have to duplicate the code for other models that
 might want to use an enum field.

So abstract just the part that grabs the enum, and put it in AppModel.

 - that snippet doesnt work with tables with underscores, to remedy that
 you can $this-table
 rather than doing this...
 $tableName = strtolower(Inflector::pluralize($this-name));

Better yet:
$db = ConnectionManager::getDataSource($this-useDbConfig);
$tableName = $db-getFullTableName($this, false);

 Also if I create my own AppModel with the getEnumValues method in, that
 resides in my app/models directory, I get errors. It only works when I
 add the method to the cake/app_model.php class.

Hmm, what errors do you get?  To Cake, there is no difference between
loading cake/app_model.php and app/app_model.php.  There must be
something else going wrong.

 Anyway, it would be nice to get this updated in Cake, its a bit
 inconsistent to have the functionality in the scaffolding but not
 available in the model functionality. Is it just a case of submitting a
 new ticket on the trac repository to get it looked at?

Not really.  Enums are a MySQL-specific feature (who said hack? I know
I didn't!) that has no equivalent in any other database platform, and
is technically the wrong way of going about it anyway.  The proper way
is to add constraints to the field, or use a lookup table that maps
symbolic values.

 Cheers
 
 James


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



Re: display enum values in dropdown

2006-09-15 Thread nate

Sorry, the method call above should have been fullTableName(), not
getFullTableName().


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



Re: display enum values in dropdown

2006-09-15 Thread nate

Oh, and I just re-read your post, and the reason you're getting errors
is because you're putting app_model.php in app/models.  It should be in
app/.


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



Re: display enum values in dropdown

2006-09-15 Thread [EMAIL PROTECTED]

I would submit it to trac.  Submit them to make CakePHP more
generalized to support all databases the support for ENUM in the
scaffolding needs to be removed to make it more consitent with the rest
of the code that is general for all databases.  That way you know to
use ENUM (::hack, cough::) you would always have to use custom code.


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



Re: display enum values in dropdown

2006-09-15 Thread John Zimmerman
On 9/15/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
I would submit it to trac.Submit them to make CakePHP moregeneralized to support all databases the support for ENUM in the
scaffolding needs to be removed to make it more consitent with the restof the code that is general for all databases.That way you know touse ENUM (::hack, cough::) you would always have to use custom code.
The issue has been submitted to trac a couple of times and PhpNut has decided that since it was a MySQL specific issue and didn't translate to other databases that the issue would be left to be solved outside of the cake core.
I orginally posted the snippet solution that was working for me, but I am sure there are bugs as some people have reported above.The snippet is meant to be placed in /app/app_model.php, that way you don't have to put it in each individual model. Make sure to follow the example for use at the end of the snippet.
I will look at some of the issues reported above and update the snippet accordingly. I think one other person has already updated it with some improvements.

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


Re: display enum values in dropdown

2006-09-15 Thread John Zimmerman
The Baked ENUM's snippet has been updated.http://cakeforge.org/snippet/download.php?type=snippetid=242Here is also a link to one of the tickets submitted to trac with phpnut's explanation.
https://trac.cakephp.org/ticket/1110

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


Re: display enum values in dropdown

2006-09-15 Thread [EMAIL PROTECTED]

John you didn't read my suggestion.  It was suggested that they should
open a ticket to complain that CakePHP should remove it since the
generateList from enum wasn't part of the core it should be removed
from the scafolding altogether.


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



Re: display enum values in dropdown

2006-09-15 Thread John Zimmerman
On 9/15/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
John you didn't read my suggestion.It was suggested that they shouldopen a ticket to complain that CakePHP should remove it since the
generateList from enum wasn't part of the core it should be removedfrom the scafolding altogether.Sorry about that. I see what you were saying after re-reading instead of just skimming.
I agree something should be done for consistency, but removing it from scaffolding would make it nearly impossible for scaffolding to work if you are using enum types. You would just get an error, thus making it nearly useless as you would be forced to bake it and insert custom code.
Maybe an acceptable alternative would be fore scaffolding to display a warning about things like enums being partially supported with suggestions for solutions after baking. The error would only be displayed if debug was not set to 0.


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


display enum values in dropdown

2006-09-14 Thread TWIOF

I Know this has been posted before. I've been using an example from an
earlier post but it only produces one of my 5 my options.
This is in the model:

function generateRatingList() {
foreach($this-_tableInfo-value AS $field) {
if($field['name'] == 'rating') {
$enum = $field['type'];
break;
}
}
foreach(split(',', substr($enum, 6, -2)) AS $num = $name) {
$return[$name] = $name;
return $return;
}
}

and this in the controller:

$this-set('ratingArray',$this-Userreview-generateRatingList());

any ideas?


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



Re: display enum values in dropdown

2006-09-14 Thread [EMAIL PROTECTED]

http://cakeforge.org/snippet/download.php?type=snippetid=210

Perhaps try this code here.  Looks like it might be a little more
robust.


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