Hi,
I’d like to create a dropdown list for _form which is populated from an enum field in my table. I found the following link ‘http://www.yiiframework.com/wiki/303/drop-down-list-with-enum-values-for-column-of-type-enum-incorporate-into-giix#hh0’ and created …\components\ZHtml.php with the following code:
class ZHtml extends CHtml
{
public static function enumDropDownList($model, $attribute, $htmlOptions=array())
{
return CHtml::activeDropDownList( $model, $attribute, self::enumItem($model, $attribute), $htmlOptions);
}
public static function enumItem($model,$attribute) {
$attr=$attribute;
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;
}
}
Then I used it in _form, replacing the default with:
<?php echo $form->labelEx($model,‘prefix’); ?>
<?php // echo $form->textField($model,‘prefix’,array(‘size’=>4,‘maxlength’=>4)); ?>
<?php echo ZHtml::enumDropDownList( $model,‘prefix’ ); ?>
<?php echo $form->error($model,‘prefix’); ?>
My table enumYype field is named ‘prefix’ and is populated with ‘enum(‘Mr’, ‘Mrs’, ‘Ms’, ‘Dr’, ‘Rev’)’
My problem is that _form gives me ‘Fatal error: Class ‘ZHtml’ not found in C:\wamp\www\laup\protected\views\tblContacts\_form.php on line 62’. On the same error page, under the Call Stack Function column, I also get the message ‘Fatal error: Class ‘ZHtml’ not found in C:\wamp\www\laup\protected\views\tblContacts\_form.php on line 62’ and ‘require( ‘C:\wamp\www\laup\protected\views\tblContacts\_form.php’ )’. Both have ‘…\CBaseController.php:126’ undet the Call Stack Location column.
My best guess as a Newbie is that I’m not pointing to the Class properly, or I may need an addition line of code to tie all ths together, but don’t know where it goes. …maybe in a Controller??
Can anyone help with direction on this?