Question

I want to do the following: Create an array inside the main.php params section that uses a value of another array inside that params section. How can i do that?

Tried something like this:

'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

The part between ** needs to point to the previous declared array. How to do that?

Was it helpful?

Solution 3

I changed the configuration of main.php in this:

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

That way i can use the previous declared array inside the next and i keep settings together for a readable format. So settings for one page are clustered.

Thanx for your feedback!

OTHER TIPS

You can move services_type to a variable and use it in two places:

$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

....

Remember that the config file is just PHP; you can use variables, functions, includes, etc.

Pull the declaration of that array outside the params array declaration:

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

And then

'params'=>array(
    'service_types'=> $service_types
    'st_open'=>array(
        $service_types['st_retour'] => array(...)
    ),
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top