Difference between #1 and #5 of
Drop down list with enum values for column of type ENUM >+> incorporate into giix

Changes

Title unchanged

Drop down list with enum values for column of type ENUM >+> incorporate into giix

Category unchanged

How-tos

Yii version unchanged

Tags changed

drop down list, input, forms, views, enum, giix, activeDropDownList

Content changed

[...]
Create the file `..\components\ZHtml.php` with the following code:

```php
class ZHtml extends CHtml
{

 
/**
 
 * This code was contributed by zaccaria in the forum:
 
 * http://www.yiiframework.com/forum/index.php?/topic/10079-enum-db-type-in-yii/ 
 
 * This method generates a drop down list for columns of type ENUM.
 
 * @param CModel $model The data model.
 
 * @param string $attribute The attribute.
 
 * @param array $htmlOptions Addtional HTML options.
 
 * @return string The generated drop down list with the enum values for the attribute.
 
 */

public static function enumDropDownList($model, $attribute, $htmlOptions=array())
{
[...]
self::resolveName($model,$attr);
preg_match('/\((.*)\)/',$model->tableSchema->columns[$attr]->dbType,$matches);
foreach(explode(
"','", $matches[1]) as $value) {
$value=str_replace("'",null,$value);
$values[$value]=Yii::t('enumItem',$value);
}
return $values;
}
[...]
10 0
11 followers
Viewed: 51 281 times
Version: 1.1
Category: How-tos
Written by: c@cba
Last updated by: nsanden
Created on: Feb 12, 2012
Last updated: 10 years ago
Update Article

Revisions

View all history