关于模型事件的使用的问题

我为 Model 在application.behaviors下创建了一个行为

class CFileCache extends CActiveRecordbehavior


{	


	public function events(){


		return parent::events();


	}


	


	public function afterFind($event)


	{


		echo '<div style="color:#FA0;">当在删除后,我被执行了!</div>';


	}


}

同时在模型中,做了行为绑定

//行为绑定


public function behaviors()


{


	return array('CFileCache'=>'application.behaviors.CFileCache');


}

为什么我在做数据库查询的时候没有任何输出呢?

Quote

我为 Model 在application.behaviors下创建了一个行为
class CFileCache extends CActiveRecordbehavior


{	


	public function events(){


		return parent::events();


	}


	


	public function afterFind($event)


	{


		echo '<div style="color:#FA0;">当在删除后,我被执行了!</div>';


	}


}

同时在模型中,做了行为绑定

//行为绑定


public function behaviors()


{


	return array('CFileCache'=>'application.behaviors.CFileCache');


}

为什么我在做数据库查询的时候没有任何输出呢?

应该是这样定义 behaviors:



        public function behaviors(){


                return array(


                        'CFileCache' => array(


                                'class' => 'CFileCache',


                        )


                );


        }





具体你可以查查手册

Quote

应该是这样定义 behaviors:


        public function behaviors(){


                return array(


                        'CFileCache' => array(


                                'class' => 'CFileCache',


                        )


                );


        }





具体你可以查查手册

我看了cook book 有两种写法 ,一种像引用中写的那样以数组做参数的,一种就是我用到那种以字符串做参数!  都试了下,貌似没什么效果  … :o

忘记说了 ,感谢 will 作答  ;)

终于弄出来了,发现一个问题,也就是是我遇到的问题

我的一个是表单模型(FModel),另一个是AR模型(ARModel)…

在FModel中,我写了一个校验方法,其中调用了ARModel的一个方法,来返回结果.用于校验…

问题是,我在控制器中调用的FModel才能执行行为绑定么?是不是在FModel中调用的ARModel就无法进行行为绑定了呢?