almost 4 years ago
protected/config/main.php
<?php
  'components'=>array(
    'joel'=>array(
      'class'=>'Joel',
      'speed' => 'slow',
    ),
  )
protected/components/Joel.php
<?php
class Joel extends CApplicationComponent
{
    public $speed = 'Fast';
    protected $sex = 'Man';
    private $_name;
    
    public function setName($name)
    {
        $this->_name = $name;
    }
    
    public function getName()
    {
        return $this->_name;
    }
}
protected/controllers/TestController.php
<?php
  Yii::app()->joel->setName('ticket01');
  echo Yii::app()->joel->getName();
  echo Yii::app()->joel->speed;
← Yii controller action 跟 view path 之間的關係 Yii customise the CLinkPager →