Update: The correct answer to this post can be found here: stack overflow
Well, you are very close to this, but you are not using the Url plugin. If you are a little immersed in the ZF2 Documentation controller plugins, you might find a solution.
See link: ZF2 Documentation - Controller Plugins
Your ConsoleController must do one of the following in order to be able to retrieve controller plugins:
AbstractActionControllerAbstractRestfulControllersetPluginManager
Well, I recommend extending your controller using AbstractActionController if you haven't already.
If you use AbstractActionController , you can simply call $urlPlugin = $this->url() , since AbstractActionController has an __call() implementation that retrieves the plugin for you. But you can also use: $urlPlugin = $this->plugin('url');
So, to generate a URL for your mail, you can do the following in your controller:
$urlPlugin = $this->url(); $urlString = $urlPlugin->fromRoute( 'route/myroute', array( 'param1' => $param1, 'param2' => $param2 ), array( 'option1' => $option1, 'option2' => $option2 ) );
You can now pass this URL to your viewModel or use the viewModel URL in your viewModel, but that is up to you.
Try to avoid viewHelpers inside your controller as we have plugins available for this case.
If you are wondering what methods AbstractActionController has, here ZF2 ApiDoc is AbstractActionController
To do this, you need to configure the route configuration with the appropriate structure:
// This can sit inside of modules/Application/config/module.config.php or any other module config. array( 'router' => array( 'routes' => array( // HTTP routes are here ) ), 'console' => array( 'router' => array( 'routes' => array( // Console routes go here ) ) ), )
If you have a console module, just stick to the console route paths. Do not forget the console key with all the routes under it! Take a look at the documentation for reference: ZF2 - Documentation: console routes and routing