【发布时间】:2023-03-24 05:01:01
【问题描述】:
我想将服务控制器实现为不从 fosRestController 扩展的休息控制器,这意味着我自己注入服务。但我总是得到以下错误:
无法在 api.contact_controller:postContactAction 中找到“api.contact_controller: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>
【问题讨论】:
标签: symfony dependency-injection fosrestbundle