Yii System Params From Database. Yii::app()->Getparams() Not Giving Results

I have extended CWebApplication as following to add params (Application-level parameters) from database. but as of now, i dont get anything when i try to retrieve params using

echo Yii::app()->params[‘adminMobileNo’];

extended code,


class QelasyApplication extends CWebApplication

{

    const PARAM_CACHE = 'params';


    public function setParams($value)

    {

        echo 'test 1';

        exit;

        $params = parent::getParams();

        print_r($params);

        echo 'test 2';

        exit;


        $value = Yii::app()->cache->get(self::PARAM_CACHE);

        if ($value === false) {

            $model = new SystemParam();

            $value = $model->getParam();

            print_r($value);

            echo 'test 3';

            exit;

            Yii::app()->cache->add(self::PARAM_CACHE, $value, 1800);

        }


        foreach ($value as $k => $v)

            $params->add($k, $v);

    }

}

in the main index.php


require_once($yii);

require_once($protected.'components/QelasyApplication.php');

$application = new QelasyApplication($config);

$application->run();

and in a controller, i am trying to access the params as


        Yii::app()->params['abc'] = 123;

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

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

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

//        print_r(Yii::app()->getParams());

exit;

but no output it just exits.

even the setParams method isnt running, coz the echo statements inside are not displayed. what could be the reason ?

why can’t you just write a component and include that in your config extending the CWebApplication. I would not recommend it.

@alirz23

could you please provide an example. tnx.

straight forward harness the power of YII





<?php

// create a new file and save it

class LoadParams extends CApplicationComponent {

 

	public function init() {

                // put your code here

		parent::init();

	}

}


// add this in your config/main.php

// The 'loadParams' component will pre-load

'preload'=>array('loadParams'),

 

// application components

'components'=>array(

	'loadParams'=>array(

		'class'=>'path.to.LoadParams', // in my case application.components.LoadParams

	),

),