3

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.

3

1 Answer 1

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');
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.