<legend id='I4nn3'><style id='I4nn3'><dir id='I4nn3'><q id='I4nn3'></q></dir></style></legend>

      • <bdo id='I4nn3'></bdo><ul id='I4nn3'></ul>
    1. <i id='I4nn3'><tr id='I4nn3'><dt id='I4nn3'><q id='I4nn3'><span id='I4nn3'><b id='I4nn3'><form id='I4nn3'><ins id='I4nn3'></ins><ul id='I4nn3'></ul><sub id='I4nn3'></sub></form><legend id='I4nn3'></legend><bdo id='I4nn3'><pre id='I4nn3'><center id='I4nn3'></center></pre></bdo></b><th id='I4nn3'></th></span></q></dt></tr></i><div id='I4nn3'><tfoot id='I4nn3'></tfoot><dl id='I4nn3'><fieldset id='I4nn3'></fieldset></dl></div>

        <small id='I4nn3'></small><noframes id='I4nn3'>

        <tfoot id='I4nn3'></tfoot>

        Yii中如何使用事件

        How to use events in Yii(Yii中如何使用事件)

          <tbody id='LcSEi'></tbody>
        <i id='LcSEi'><tr id='LcSEi'><dt id='LcSEi'><q id='LcSEi'><span id='LcSEi'><b id='LcSEi'><form id='LcSEi'><ins id='LcSEi'></ins><ul id='LcSEi'></ul><sub id='LcSEi'></sub></form><legend id='LcSEi'></legend><bdo id='LcSEi'><pre id='LcSEi'><center id='LcSEi'></center></pre></bdo></b><th id='LcSEi'></th></span></q></dt></tr></i><div id='LcSEi'><tfoot id='LcSEi'></tfoot><dl id='LcSEi'><fieldset id='LcSEi'></fieldset></dl></div>

        <small id='LcSEi'></small><noframes id='LcSEi'>

            <bdo id='LcSEi'></bdo><ul id='LcSEi'></ul>
            <tfoot id='LcSEi'></tfoot>

          • <legend id='LcSEi'><style id='LcSEi'><dir id='LcSEi'><q id='LcSEi'></q></dir></style></legend>

                  本文介绍了Yii中如何使用事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 onBeginRequest 事件中运行一些代码.
                  我在哪里做?我假设我不应该在核心库代码中添加它.
                  我是 Yii 的菜鸟

                  I want to run some code in the onBeginRequest event.
                  Where do I do that? I assume I am not suppose to add this in the core library code.
                  I am a totally noob in Yii

                  推荐答案

                  如果你想使用 onBeginRequest 和 onEndRequest 你可以通过在你的配置文件中添加下一行来实现:

                  If you want to use onBeginRequest and onEndRequest you can do it by adding the next lines into your config file:

                  return array (
                  ...
                  'onBeginRequest'=>array('Y', 'getStats'),
                  'onEndRequest'=>array('Y', 'writeStats'),
                  ...
                  )
                  

                  或者你可以内联

                  Yii::app()->onBeginRequest= array('Y', 'getStats');
                  Yii::app()->onEndRequest= array('Y', 'writeStats');
                  

                  其中 Y 是一个类名,getStatswriteStats 是这个类的方法.现在假设你有一个类 Y 声明如下:

                  where Y is a classname and getStats and writeStats are methods of this class. Now imagine you have a class Y declared like this:

                  class Y {
                      public function getStats ($event) {
                          // Here you put all needed code to start stats collection
                      }
                      public function writeStats ($event) {
                          // Here you put all needed code to save collected stats
                      }
                  }
                  

                  因此,对于每个请求,这两种方法都会自动运行.当然你会想为什么不简单地重载 onBeginRequest 方法呢?"但首先,事件允许您不扩展类来运行一些重复的代码,并且它们允许您执行在不同地方声明的不同类的不同方法.所以你可以添加

                  So on every request both methods will run automatically. Of course you can think "why not simply overload onBeginRequest method?" but first of all events allow you to not extend class to run some repeated code and also they allow you to execute different methods of different classes declared in different places. So you can add

                  Yii::app()->onEndRequest= array('YClass', 'someMethod');
                  

                  在您的应用程序的任何其他部分以及以前的事件处理程序,您将在请求处理后运行 Y->writeStatsYClass->someMethod.这与行为允许您创建几乎任何复杂性的扩展组件,而无需更改源代码,也无需扩展 Yii 的基类.

                  at any other part of your application along with previous event handlers and you will get run both Y->writeStats and YClass->someMethod after request processing. This with behaviors allows you create extension components of almost any complexity without changing source code and without extension of base classes of Yii.

                  这篇关于Yii中如何使用事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <i id='fizOV'><tr id='fizOV'><dt id='fizOV'><q id='fizOV'><span id='fizOV'><b id='fizOV'><form id='fizOV'><ins id='fizOV'></ins><ul id='fizOV'></ul><sub id='fizOV'></sub></form><legend id='fizOV'></legend><bdo id='fizOV'><pre id='fizOV'><center id='fizOV'></center></pre></bdo></b><th id='fizOV'></th></span></q></dt></tr></i><div id='fizOV'><tfoot id='fizOV'></tfoot><dl id='fizOV'><fieldset id='fizOV'></fieldset></dl></div>
                    <bdo id='fizOV'></bdo><ul id='fizOV'></ul>

                            <tbody id='fizOV'></tbody>

                          <small id='fizOV'></small><noframes id='fizOV'>

                        • <tfoot id='fizOV'></tfoot>

                          • <legend id='fizOV'><style id='fizOV'><dir id='fizOV'><q id='fizOV'></q></dir></style></legend>