0

Let's say i have a FooController extending Craft\BaseController located somewhere else (not in a plugin). The FooController is autoloaded via composer and the autoload.php is included in public/index.php

Would there be a way to route to this FooController? Is it not possible with Craft (or Yii) to just say something laravel like: Route::get('foo/bar', 'FooController@bar')?

Edit (follow up question): If I have something like this in my registerSiteRoutes function:

 return [
     'foo/bar' => ['action' => 'plugin/foo/bar', 'additional' => 'acme'],
 ];

Would I be able to access the 'additional' information in the controller?

  • I am leaving this as a comment, because I am not confident enough it's correct enough to post this an answer. But based on my experience, you need to have it located in the controllers directory in your plugin. One option, again perhaps not the only or best option, would be to use a controller in the controller directory that is merely a wrapper to call the function elsewhere. Just a thought. – Justin Kimbrell Jan 9 '15 at 19:59
1

As it turns out it's not really possible to break out of the intended craft workflow. If you don't want to put additional business logic in plugins, you're only option is changing the index file. Which I did like this:

try
{
    $app->run();
}
catch(CHttpException $exception)
{
    // Implement custom route logic here
    // If nothing matches your own routes, just rethrow the $exception
    // like so:
    //throw $exception;
}

I'm more playing around here the learn how craft works, in the end the best solution is probably to just go with a plugin.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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