YII中的CComponent基础类
发布日期:2021-05-10 09:42:10 浏览次数:17 分类:精选文章

本文共 3682 字,大约阅读时间需要 12 分钟。

###Yii������CComponent���������������������

####������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Yii���������CComponent������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������App������������������������������������$cache���������������������$db������������������������������������������������������������������������������������������������������������$db���������������������������������������������������������������

CComponent���������������������__get���__set������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

####������������

���������������������������������������������������������������������������Yii���������������������������������������������������������������������������������������������������������������������

������������������������������������������������������

  • ���������������������������������������on������������������������������������public function onBtnClick()���������������������������������������������

  • ���������������������������attachEventHandler������������������������������������������������������������������������������������

    $component->attachEventHandler('btnClick', function ($event) {
    // ������������������
    });
  • ���������������������������������������������������raiseEvent������������������������������������������

    $component->raiseEvent('btnClick', new ButtonClickEvent($data));
  • CComponent���������������������������$event���������������������������������������������������������������������������������������������������������������������������������������������������������

    ####���������������

    ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    ���������������������������������

  • ������������������������CBehavior���������������������������������������������������������������������������

    class CalculatorBehavior extends CBehavior {
    public function add($x, $y) {
    return $x + $y;
    }
    }
  • ���������������������attachBehavior������������������������������������CComponent������������������

    $component->attachBehavior('calculator', new CalculatorBehavior());
  • ������������������������������������������������������������������������������������������

    $component->add(2, 5); // ������������CalculatorBehavior���add������
  • CComponent���������__get���__set���__call������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    ###������

    CComponent������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    ���������������������Yii������������������������������������������������������������������������������������������������������������������������������������������

    上一篇:YII建立多语言
    下一篇:yii的relations方法的使用

    发表评论

    最新留言

    留言是一种美德,欢迎回访!
    [***.207.175.100]2025年04月22日 15时52分49秒