<p>Off the top of my head and in no way tested or thought through, you could put some logic in your plugin's <code>init()</code> method:</p>

<pre><code>public function init()
{
    $username = craft()-&gt;request-&gt;getQuery('username');

    if ($username)
    {
        craft()-&gt;urlManager-&gt;setRouteVariables(array(
            'username' =&gt; $username
        ));

        craft()-&gt;runController('myPluginHandle/myPluginActionMethod');
    }
}
</code></pre>

<p>Then in your plugins's controller:</p>

<pre><code>class MyPluginController extends BaseController
{
    protected $allowAnonymous = true;

    public function actionDoIt($username)
    {
        // Do your thing.

        $this-&gt;redirect('homepage');
    }
}
</code></pre>

CC BY-SA 3.0
2015-02-28T05:18:43.797Z
2015-02-28T05:18:43.797Z
Brad Bell
<p>I want to create an event that triggers before the site loads to I grab the variables passed in the http header and send them to a plugin I have made.</p>

<p>I will have a url like <a href="http://www.foo.com?username=abc123" rel="nofollow">http://www.foo.com?username=abc123</a></p>

<p>I want it immediately trigger a controller method located at: <a href="http://www.foo.com/actions/myPlugin/myMethod" rel="nofollow">http://www.foo.com/actions/myPlugin/myMethod</a></p>

<p>Im just not sure how to connect the dots.</p>

CC BY-SA 3.0
2015-02-27T18:18:43.940Z
Would you want it to redirect to http://www.foo.com/actions/myPlugin/myMethod or just execute it, but keep the http://www.foo.com/?username=abc123 URL?
Brad Bell
CC BY-SA 3.0
2015-02-28T02:12:54.087Z
I need it to execute it, then I will be redirecting to the index page
ConquestXD
CC BY-SA 3.0
2015-05-29T08:09:32.127Z
Didn't the approach Brad posted work for you?
carlcs
<events>
Create event before site loads
# Create event before site loads

(Asked by: username_0 on 2015-02-27)

I want to create an event that triggers before the site loads to I grab the variables passed in the http header and send them to a plugin I have made.

I will have a url like <http://www.foo.com?username=abc123>

I want it immediately trigger a controller method located at: <http://www.foo.com/actions/myPlugin/myMethod>

Im just not sure how to connect the dots.

**Tags:** events
> **Comments:**
> **username_1**: Would you want it to redirect to http://www.foo.com/actions/myPlugin/myMethod or just execute it, but keep the http://www.foo.com/?username=abc123 URL?  
> **username_0**: I need it to execute it, then I will be redirecting to the index page  
> **username_2**: Didn't the approach Brad posted work for you?  

---

## 1 answers

### Answer by username_1 on 2015-02-28. Score: 1

Off the top of my head and in no way tested or thought through, you could put some logic in your plugin's init() method:
public function init()
{
    $username = craft()->request->getQuery('username');

    if ($username)
    {
        craft()->urlManager->setRouteVariables(array(
            'username' => $username
        ));

        craft()->runController('myPluginHandle/myPluginActionMethod');
    }
}

Then in your plugins's controller:
class MyPluginController extends BaseController
{
    protected $allowAnonymous = true;

    public function actionDoIt($username)
    {
        // Do your thing.

        $this->redirect('homepage');
    }
}


---

