【问题标题】:Symfony restbundle argument for custom service controller non given未给定自定义服务控制器的 Symfony restbundle 参数
【发布时间】: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


    【解决方案1】:

    现在它的工作方式如下:

    路由定义

    contact:
        type: rest
        resource: "api.contact_controller"
    

    没有任何动作!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多