Can I modify the application settings from within the application

Can I modify the application settings from within the application (maybe from inside a component) without having to manually change the configs file (config/main.php)?

Up, someone please.

if you mean what i think you mean then yes, for example: you might want to change the language of the application, you can set it in the config file


you could also do this in a controller

Yii::app()->language = 'en_us';



That’s perfect because many of the settings should be editable from the site settings area and avoid sending users to a file rather than using their browser.

What jayrulez suggested will only keep the changed setting for the given request. It will not remember the setting across multiple requests… You would need to interact with the database to do that.

You can try this:

I haven’t tried yet, so please report if it works :)

I’m doing in the bootsrap with a singleton but some parameters fail to be overwritten:

$yiiApp = Yii::createWebApplication ( $config );

$settings = WB_Settings::getInstance ();

app ()->name = $settings->getSetting ( 'SITE_NAME' );

app ()->components [ 'db' ]->enableProfiling = $settings->getSetting ( 'RUN_ON_DEVELOPMENT' );

$yiiApp->run ();

For example

app ()->components [ 'db' ]->enableProfiling = $settings->getSetting ( 'RUN_ON_DEVELOPMENT' ); 


$settings->getSetting ( 'RUN_ON_DEVELOPMENT' );

is set to FALSE in the database does not close the database profiler. I will have a look at the article suggested and post updates.

Maybe I’m overwriting the settings wrong but on a print_r I can see enableProfiling set to 0 but it still loads so it must be a trick somewhere. Maybe qiang can help or someone who did this before.

Forgot to say that app() is a shortcut function for Yii::app ()