zoukankan      html  css  js  c++  java
  • [Yii Framework] 创建自己的extension

    创建application component
    继承IApplicationComponent接口,或者继承CApplicationComponent类,一定要覆盖IApplicationComponent::init()这个方法,因为component的实例化的时候要做一些准备工作的。

    创建behavior
    继承IBehavior接口,或者继承CBehavior类,
    如果是为CModel或者CActiveRecord开发behaviors的话,可以继承CModelBehavior或者CActiveRecordBehavior,这些基类为CModel和CActiveRecord提供了额外的功能。
    例如,继承CActiveRecordBehavior,在model里面使用这个behavior的时候,可以这个behavior可以影响到原来的CActiveRecord的基类方法的。如,


    class TimestampBehavior extends CActiveRecordBehavior
    {
    public function beforeSave($event)
    {
    if($this->owner->isNewRecord)
    $this->owner->create time=time();
    else
    $this->owner->update time=time();
    }
    }


    在comment的model里面


    Public function behaviors()
    {
    return array(
    'AutoTimestampBehavior'=> array(
    'class' => 'application.components.AutoTimestampBehavior',
    //You can optionally set the field name options here
    )
    );
    }

  • 相关阅读:
    linux 环境下安装oracle11g方法及安装过程中遇上的问题解决方法
    Opencv Mat的操作
    Opencv 的数据结构
    Opencv 摄像头矫正
    LM算法
    Python 正则表达式
    find grep
    Socket 入门
    Python thread
    Javascript实现页面跳转的几种方式
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/1717035.html
Copyright © 2011-2022 走看看