My question is, what do I have to do to access those two config params (url and key)?
Are they created automatically? Do I need to create getters and setters for each? What are the relationships between member variable names and the parameter names if any?
I've been looking through the code and doc and I'm just lost.
You just need to declare 'url' and 'key' public member variables in your component class, and they will be filled with the supplied values. You may also define such properties using getter/setter.
Thanks, but that doesn't seem to work. Here's my class…
<?php
class CMyComponent extends CComponent
{
public $key = '';
public $url = '';
public function init()
{
// Call daddy...
parent::init();
}
public function getKey()
{
return( $this->key );
}
public function getUrl()
{
return( $this->url );
}
public function setKey( $sKey )
{
$this->key = $sKey;
}
public function setUrl( $sUrl )
{
$this->url = $sUrl;
}
}
?>
In addition, my init() function doesn't ever seem to be called… Maybe that's the problem?
By default, the component will be created/initialized only when you call Yii::app()->myComp for the first time. If you want it to be created all the time, you should list its ID 'myComp' in the 'preload' property of app.
Qiang, thanks! I got it working with the getters and setters.
Just so I'm clear…
If I provide public members that match the parameter names in main.php, they will be automatically set. If the member names do not match, then I must provide getters and setters? And by match I mean same case, same name (i.e. 'key' in params file matches public $key in php file). Or must I always provide a getter and setter for a member variable/config parm?