我想实现服务控制器作为休息控制器,而不是从fosRestController扩展,这意味着我自己注入服务。但我总是得到错误:
无法在api.contact_controller中找到“api.contact_controller:postContactAction”控制器:postContactAction(从“/var/www/XXXX/XXXXX/XXXXX/app/config/routing.yml”导入)。
服务类:
api.contact_controller:
class: XXXX\ApiBundle\Controller\ContactController
parent: XXXX_rest_controller
arguments: [ "@templating"]
然后路由:
contact:
type: rest
resource: 'api.contact_controller:postContactAction'
最后是控制器
namespace XXXXX\ApiBundle\Controller;
use FOS\RestBundle\Routing\ClassResourceInterface;
use XXXXX\ContentBundle\Form\ContactFormType;
use XXXXX\Frontend\Controller\RestController;
use XXXX\Frontend\Model\Contact;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Class ContactController
*
* @package XXXXX\ApiBundle\Controller
*/
class ContactController extends RestController
{
/**
* @var EngineInterface $templating
*/
private $templating;
/**
* ContactController constructor.
* @param EngineInterface $templating
*/
public function __construct (EngineInterface $templating)
{
}
public function postContactAction (Request $request)
{
echo '<pre>';
print_r($request);die;
}
}
表格:
<form id="contactform" method="post" action="{{ path('post_contact') }}" name="contactform">
.....
</form>
答案 0 :(得分:0)
现在它的工作原理如下:
contact:
type: rest
resource: "api.contact_controller"
没有行动!