Php 如何在Yii框架中使用两个itemAlias?

Php 如何在Yii框架中使用两个itemAlias?,php,yii,Php,Yii,我试图在我的项目中的一个模型中使用两个itemAlias,但当我运行程序时,浏览器上没有显示任何内容。这是我的模型: public static function itemAlias($type,$code=NULL) { $_items = array( 'Category' => array( '1' => 'Administration', '2' => 'Faculty',

我试图在我的项目中的一个模型中使用两个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的表单:


有什么问题吗?

很遗憾,我的程序编码错误,可能会使用两个或多个项目别名,您应该将其放在$\u 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;
}
我试过了,它解决了我的问题,谢谢大家

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;
}