我想自定义component,然后在Yii应用中使用,怎么写啊?
看官方文档只是原理,具体怎么用啊?
有人知道呗?
我想自定义component,然后在Yii应用中使用,怎么写啊?
看官方文档只是原理,具体怎么用啊?
有人知道呗?
你去down一个component,看看别人的例子,就好呀。
姐姐,我去哪里down啊?
你没发现那些插件(扩展)吗?
这要看你的用途,你可以继承CComponent
算了,我还是看源代码去吧!
还是感谢上面的仁兄回帖!
我定义了自己的一个组件类,如下:
class Mycomponent extends CComponent
{
public function init()
{
$this->onTestEvent = 'eventHandler';
}
public function onTestEvent(){}
function eventHandler($event)
{
echo "onTestEvent";
}
}
上面很明显是一个事件,然后我在一个controller里面触发这个事件,代码如下:
class SiteController extends CController
{
public function actionIndex()
{
$event = new CEvent($this);
Yii::app()->mycomponent->raiseEvent('onTestEvent',$event);
$this->render('index');
}
}
可是,当执行到触发的那段代码时候就会报错,错误如下:
call_user_func(eventHandler) [<a href=‘function.call-user-func’>function.call-user-func</a>]:
First argument is expected to be a valid callback
代码是在执行CComponent类的“call_user_func($handler,$event);”这句时报错了!
什么意思?有人能帮助我吗?
还是我使用事件错了!