40 lines
663 B
PHP
40 lines
663 B
PHP
<?php
|
|
namespace app\components;
|
|
|
|
use yii\base\Behavior;
|
|
|
|
class MyBehavior extends Behavior{
|
|
public $prop1;
|
|
private $_prop2;
|
|
private $_prop3;
|
|
|
|
//绑定事件和处理器,从而扩展类的功能表现,这里体现了“行为”字面意义
|
|
public function events()
|
|
{
|
|
|
|
}
|
|
|
|
//行为的只读属性
|
|
public function getProp2()
|
|
{
|
|
return $this->_prop2;
|
|
}
|
|
|
|
//行为的只写属性
|
|
public function setProp3($prop3)
|
|
{
|
|
$this->_prop3 = $prop3;
|
|
}
|
|
|
|
//行为的方法
|
|
public function foo()
|
|
{
|
|
return 'foo';
|
|
}
|
|
|
|
protected function bar()
|
|
{
|
|
return 'bar';
|
|
}
|
|
|
|
} |