Yii 1.1: Define general array and variable and call it to anywhere in application

3 followers

Create param.php file in protected/config

Yii::app()->params['TEXT_ACTIVE'] = 'Active'; //1 for active
 
Yii::app()->params['AD_LAYOUT_POISITION'] = array(
    "1" => array(
        'width' => '1000',
        'height' => '150'
    ),
    "2" => array(
        'width' => '200',
        'height' => '150'
    ),
    "3" => array(
        'width' => '1000',
        'height' => '150'
    ),
    "4" => array(
        'width' => '200',
        'height' => '150'
    ),
);

Now include this file in protected/config/main.php

require_once( dirname(__FILE__) . '/params.php');
return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
         ....

Now suppose I have to call TEXT_ACTIVE I will write in my file as

echo Yii::app()->params['TEXT_ACTIVE'];

Total 2 comments

#11497 report it
yiqing95 at 2013/01/16 09:59pm
there are some similar things do this task

for static params this solution is ok 。

see setting-and-getting-systemwide-static-parameters

for dynamic params often save it to db and can modify it from GUI(web ui) , see this great extension :settings

#11486 report it
bhavesh vaghela at 2013/01/16 09:56am
Is it useful ?

If anyone has new idea about how to set general variable and get anywhere in system , any comment related article will be appreciated

Leave a comment

Please to leave your comment.

Write new article