<p>Yii fires the onBeginRequest event before Craft has had a chance to do any of the plugin bootstrapping / initialization, which is why it's not firing in your plugin.</p>

CC BY-SA 3.0
2014-08-08T17:08:39.030Z
2014-08-08T17:08:39.030Z
Brad Bell
<p>I want to listen for Yii events like onBeginRequest and onEndRequest. I've tried the following but nothing happens :( </p>

<pre><code>\Yii::app()-&gt;onBeginRequest = create_function('$event', 'die ("YO") ;');
</code></pre>

<p>and </p>

<pre><code>craft()-&gt;attachEventHandler('onBeginRequest', array($this, 'dieyo'));
</code></pre>

<p>and</p>

<pre><code>craft()-&gt;getEventHandlers('onBeginRequest')-&gt;add(array($this, 'dieyo'));
</code></pre>

<p>-</p>

<pre><code>public function dieyo($event)
{
    craftdd($event);
}
</code></pre>

<p>Thanks in advance</p>

CC BY-SA 3.0
2014-08-08T14:49:21.870Z
Did some more testing "onEndRequest" works fine. So I guess onBeginRequest is a loader and/or timing issue?
pythic
<plugin-development><events>
Is it possible to listen for Yii events?
# Is it possible to listen for Yii events?

(Asked by: username_0 on 2014-08-08)

I want to listen for Yii events like onBeginRequest and onEndRequest. I've tried the following but nothing happens :( 
\Yii::app()->onBeginRequest = create_function('$event', 'die ("YO") ;');

and 
craft()->attachEventHandler('onBeginRequest', array($this, 'dieyo'));

and
craft()->getEventHandlers('onBeginRequest')->add(array($this, 'dieyo'));

-
public function dieyo($event)
{
    craftdd($event);
}

Thanks in advance

**Tags:** plugin-development, events

> **Comments:**
> **username_0**: Did some more testing "onEndRequest" works fine. So I guess onBeginRequest is a loader and/or timing issue?  

---

## 1 answers

### Answer by username_1 on 2014-08-08. Score: 2 | Accepted answer

Yii fires the onBeginRequest event before Craft has had a chance to do any of the plugin bootstrapping / initialization, which is why it's not firing in your plugin.


---

