2

I am developing a website using Yii. I want to change the application name dynamically in program. I know I have to change the Yii::app()->name value. But I know where should I put it to overwrite what is written in config.php file.

Where should I put it?

hd.
  • 17,596
  • 46
  • 115
  • 165
  • Can you explain *why* you want to change the app name? @iodragon is right, this can be quite dangerous. And please give a better reason than "I need it" ;). – Michael Härtl Oct 06 '13 at 08:57

3 Answers3

3

$name is a public value of CApplication, you can just set it theoretically.

But this is not a good idea, the name is used in getId() function, and the id is used as keyPrefix in cache and maybe anywhere else. So don't change the application name dynamically.

If what you want is changing the page title dynamically, you can just set the CController::$pageTitle.

iodragon
  • 334
  • 1
  • 4
1

Old question maybe but I just spent an hour fixing this and couldnt find an easy fix so here it is:

You can change Yii::app()->name dynamically as long as you are not using any caching component.

If you are using caching you can still set the name variable dynamically if you give the entire application a static id (the id variable of the CApplication class).

This is because the CWebUser component prefixes a stateKeyPrefix variable to the session lookup, which if not set looks for the CApplication id which if not set is a hashed version of the application name. So if you set either of these variables in your configuration file you are good to go.

Julian
  • 54
  • 2
0

Why do you need to change it? Anywhere you are displaying Yii::app()->name just use something like getAppName() and write a function to pull it out of the database.

Pitchinnate
  • 7,517
  • 1
  • 20
  • 37