Answer the question
In order to leave comments, you need to log in
How to call a non-action method when declaring a controller as a service?
How to call a non-action method when declaring a controller as a service?
There is a controller class designated as a service
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
//...
class MyServiceController extends Controller {
/**
*
* @Route("/my/action", name="my_action")
* @Method("POST")
*/
public function myAction(Request $request)
{
// ...
}
protected function myMethod(Request $request)
{
// ...
}
}
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
//...
class MyOtherServiceController extends MyServiceController {
/**
*
* @Route("/my/other/action", name="my_other_action")
* @Method("POST")
*/
public function myAction(Request $request)
{
// ...
}
protected function myMethod(Request $request)
{
// ...
}
}
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
//...
class MyController extends Controller {
/**
* @Route("/my/controller", name="my_controller")
* @Method("POST")
*/
public function serviceAction(Request $request)
{
// Срабатывает успешно.
$this->forward('app.service.myAction', array(
'request' => $request,
));
// не срабатывает
$this->forward('app.service.myMethod', array(
'request' => $request,
));
}
}
app.service:
class: AppBundle\Controller\MyOtherServiceController
arguments: []
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question