Domanda

We are building a web application using Yii as the framework. Where would be a good location for us to put a version information array?

This version array is not the version of Yii but the version our application is on. This way we can use it global throughout the application. Example when deploy the application on our servers we can have a conditional that compares the required_php_version against the server's php version (phpversion()) to throw errors. This is just a simple example.

The array would consist of (with possibility to evolve later):

<?php
array(
    'version' => '2.0.1',
    'required_php_version' => '5.4.4'
);
?>
È stato utile?

Soluzione

As far as I know, The best place to put your configurations in an application based on Yii, is main.php config file, which is situated in protected/config/main.php. But it is important to put your custom configurations in a right place. That is in params array. You can put your configs like below in config file:

'params' => array(
    'webmaster' => 'YourEmail@example.com',
    'required_php_version' => '5.4.1',
    'my_app_version'=>'2.0.1.1',
    'info_in_array'=>array(1,2,3,4,'so on ...')
    // and so on
 ),

You can use these information in everywhere of your application like below:

Yii::app()->params['required_php_version'] //which returns 5.4.1 in this example.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top