使用自定义方法控制器进行自定义路线

时间:2019-11-19 16:38:01

标签: symfony4 api-platform.com

我为PUT项目操作创建了一个自定义控制器。我使用了_invoke方法来执行默认操作,但是我尝试对同一项目的第二个PUT操作使用自定义方法。


我尝试了这种配置,但没有成功。

*         "activate"={
*             "method"="PUT",
*             "path"="/safety_rooms/{id}/activate",
*             "requirements"={"id"="\d+"},
*             "controller"=SafetyRoomPutItem::activeRoom,
*          },

但是我得到[Semantical Error] Couldn't find constant App\Controller\SafetyRoomPutItem::activeRoom, class App\Entity\SafetyRoom.


我尝试了这种配置,但没有成功。

*         "activate"={
*             "method"="PUT",
*             "path"="/safety_rooms/{id}/activate",
*             "requirements"={"id"="\d+"},
*             "controller"=SafetyRoomPutItem::class.activeRoom,
*          },

但是我得到[Syntax Error] Expected Doctrine\Common\Annotations\DocLexer::T_CLOSE_CURLY_BRACES, got '.' at position 1274 in class App\Entity\SafetyRoom.


我尝试了这种配置,但没有成功。

*         "activate"={
*             "method"="PUT",
*             "path"="/safety_rooms/{id}/activate",
*             "requirements"={"id"="\d+"},
*             "controller"=SafetyRoomPutItem::class(activeRoom),
*          },

我尝试了这种配置,但没有成功。

*         "activate"={
*             "method"="PUT",
*             "path"="/safety_rooms/{id}/activate",
*             "requirements"={"id"="\d+"},
*             "controller"=SafetyRoomPutItem::class:activeRoom,
*          },

我尝试了这种配置,但没有成功。

*         "activate"={
*             "method"="PUT",
*             "path"="/safety_rooms/{id}/activate",
*             "requirements"={"id"="\d+"},
*             "controller"=SafetyRoomPutItem:activeRoom,
*          },

我尝试了这种配置,但没有成功。

*         "activate"={
*             "method"="PUT",
*             "path"="/safety_rooms/{id}/activate",
*             "requirements"={"id"="\d+"},
*             "controller"=[SafetyRoomPutItem::class, "activeRoom"],
*          },

但是我得到[Syntax Error] Expected PlainValue, got '[' at position 1250 in class App\Entity\SafetyRoom.


1 个答案:

答案 0 :(得分:0)

确定要在使用类时声明完整的合格名称空间: use App\Controller\SafetyRoomPutItem\SafetyRoomPutItem吗?