Last active
September 24, 2015 09:26
-
-
Save luckily/37da5c897b56c61ef47c to your computer and use it in GitHub Desktop.
Yii create component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// protected/config/main.php | |
'components'=>array( | |
'joel'=>array( | |
'class'=>'Joel', | |
'speed' => 'slow', | |
), | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// protected/controllers/TestController.php | |
Yii::app()->joel->setName('ticket01'); | |
echo Yii::app()->joel->getName(); | |
echo Yii::app()->joel->speed; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
建立 Yii 1.1 component 範例