Yii Framework Forum: adding to Yii::app() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

adding to Yii::app() Rate Topic: -----

#1 User is offline   mithereal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 67
  • Joined: 14-April 10
  • Location:The Radioactive Desert, AZ

Posted 31 October 2010 - 10:15 PM

how do i add to yii::app
i want to do something like Yii::app()->company = mycompany
no info on the forums just on extending yii::app()->user
thx in advance
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 31 October 2010 - 10:59 PM

The easiest is to add it to the main configuration file (protected/config/main.php), like this:
return array(
	'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
	'name' => 'MyWebApp',
	'company' => 'Me Incorporated',

Then you should be able to use Yii::app()->company.
"Less noise - more signal"
0

#3 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 31 October 2010 - 11:32 PM

If you want to extend, use runApplication method. You can pass it a class name.
You can also use params property:

// your application config:
'params'=>array(
    'company'=>'My Company',
),

0

#4 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 01 November 2010 - 04:08 AM

View Postjacmoe, on 31 October 2010 - 10:59 PM, said:

The easiest is to add it to the main configuration file (protected/config/main.php), like this:
return array(
	'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
	'name' => 'MyWebApp',
	'company' => 'Me Incorporated',

Then you should be able to use Yii::app()->company.


This doesn't work since $company isn't a public property of CWebApplication nor does it have a setter-method.

If you really want to access via Yii::app()->company then extend the CWebApplication class (by adding public property or setter/getter method) or attach a behavior to Yii::app(). But maybe what andy_s wrote will work for you.
0

#5 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 01 November 2010 - 04:42 AM

Right, I still have some Yii learning to do..

That reminds me: I would probably use the Config extension written by Y!! ;)
I am planning to use that myself..

$company = Yii::app()->config->get('company');
Yii::app()->config->set('company', 'My Company Unlimited');





"Less noise - more signal"
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users