我正试图在我的项目中的一个模型中使用两个itemAlias
,但当我运行程序时,浏览器上不会显示任何内容。这是我的型号:
public static function itemAlias($type,$code=NULL) {
$_items = array(
'Category' => array(
'1' => 'Administration',
'2' => 'Faculty',
'3' => 'Staff',
),
);
if (isset($code))
return isset($_items[$type][$code]) ? $_items[$type][$code] : false;
else
return isset($_items[$type]) ? $_items[$type] : false;
}
public static function itemAlias($type,$code=NULL) {
$_items = array(
'Category' => array(
'1' => 'College President',
'2' => 'College Director',
'3' => 'Dean of Student Affairs',
'4' => 'Guidance Councilor',
'5' => 'MArketing Head',
'6' => 'College Registrar',
'7' => 'College Accountant',
'8' => 'School Nurse',
'9' => 'Department Head',
'10' => 'Department Coordinator',
'11' => 'Faculty',
'12' => 'Librarian',
'13' => 'Property Custodian',
'14' => 'Utility',
'15' => 'Guard',
),
);
if (isset($code))
return isset($_items[$type][$code]) ? $_items[$type][$code] : false;
else
return isset($_items[$type]) ? $_items[$type] : false;
}
这是使用itemAlias
es:的表格
<div class="row">
<?php echo $form->labelEx($model,'org_position'); ?>
<?php echo $form->dropdownlist($model,'org_position', Organization::itemAlias('Category'), array('empty' =>'select category')); ?>
<?php echo $form->error($model,'org_position'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'org_group'); ?>
<?php echo $form->dropdownlist($model,'org_group', Organization::itemAlias('Category'), array('empty' =>'select category')); ?>
<?php echo $form->error($model,'org_group'); ?>
</div>
可能是什么问题?
很遗憾,我刚刚对我的程序进行了错误编码。它可能使用两个或多个项目别名,您应该将其放在$_items数组下
public static function itemAlias($type,$code=NULL) {
$_items = array(
'PositionCategory' => array(
'1' => 'College President',
'2' => 'College Director',
'3' => 'Dean of Student Affairs',
'4' => 'Guidance Councilor',
'5' => 'MArketing Head',
'6' => 'College Registrar',
'7' => 'College Accountant',
'8' => 'School Nurse',
'9' => 'Department Head',
'10' => 'Department Coordinator',
'11' => 'Faculty',
'12' => 'Librarian',
'13' => 'Property Custodian',
'14' => 'Utility',
'15' => 'Guard',
),
'GroupCategory' => array(
'1' => 'Administration',
'2' => 'Faculty',
'3' => 'Staff',
),
);
if (isset($code))
return isset($_items[$type][$code]) ? $_items[$type][$code] : false;
else
return isset($_items[$type]) ? $_items[$type] : false;
}
我试过了,它解决了我的问题,谢谢大家!!!