yii framework main.php在params中使用其他数组的变量



我想执行以下操作:在main.php params节内创建一个数组,该数组使用该params节中另一个数组的值。我该怎么做?

尝试过这样的东西:

'params'=>array(
    //service types constants
    'service_types'=>array(
    'st_defect'=>1,
    'st_retour'=>2,
    'st_order'=>3,
    ),
//open times of department 0=monday
    'st_open'=>array(
    **service_types['st_retour']**=>array(
                              0=>array(800,1700),   
                              1=>array(800,1700),   
                              2=>array(800,1700),   
                              3=>array(800,1700),
                              4=>array(800,1700),
            ),  
        ),
), //end params array

**之间的部分需要指向上一个声明的数组。如何做到这一点?

您可以将services_type移动到一个变量并在两个位置使用它:

$service_types = array(
'st_defect'=>1,
'st_retour'=>2,
'st_order'=>3,
);
return array(     /*** .... ****/
'params'=>array(
    //service types constants
    'service_types'=>$services_types,
//open times of department 0=monday
    'st_open'=>array(
    $service_types['st_retour']=>array(
                              0=>array(800,1700),   
                              1=>array(800,1700),   
                              2=>array(800,1700),   
                              3=>array(800,1700),
                              4=>array(800,1700),
            ),  
        ),
), //end params array
....

请记住,配置文件只是PHP;您可以使用变量、函数、include等。

将该数组的声明拉到params数组声明之外:

$service_types = array(
    'st_defect'=>1,
    'st_retour'=>2,
    'st_order'=>3,
);

然后

'params'=>array(
    'service_types'=> $service_types
    'st_open'=>array(
        $service_types['st_retour'] => array(...)
    ),
)

我在以下位置更改了main.php的配置:

$ret = array();
$ret['params'] =array();
    //service types constants
    $ret['params']['service_types']=array(
    'st_defect'=>1,
    'st_retour'=>2,
    'st_order'=>3,
    );
//open times of department 0=monday
    $ret['params']['st_open']=array(
                             $ret['params']['service_types']['st_retour']=array(
                              0=>array(800,1700),   
                              1=>array(800,1700),   
                              2=>array(800,1700),   
                              3=>array(800,1700),
                              4=>array(800,1700),
            );  
        );

return $ret;

这样,我就可以在下一个数组中使用上一个声明的数组,并将设置放在一起以获得可读的格式。因此,一个页面的设置是聚集的。

感谢您的反馈!

最新更新