Skip to content

Instantly share code, notes, and snippets.

@luckily
Last active September 24, 2015 09:26
Show Gist options
  • Save luckily/37da5c897b56c61ef47c to your computer and use it in GitHub Desktop.
Save luckily/37da5c897b56c61ef47c to your computer and use it in GitHub Desktop.
Yii create component
<?php
// protected/components/Joel.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;
}
}
<?php
// protected/config/main.php
'components'=>array(
'joel'=>array(
'class'=>'Joel',
'speed' => 'slow',
),
)
<?php
// protected/controllers/TestController.php
Yii::app()->joel->setName('ticket01');
echo Yii::app()->joel->getName();
echo Yii::app()->joel->speed;
@luckily
Copy link
Author

luckily commented Sep 24, 2015

建立 Yii 1.1 component 範例

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment