Search code examples
phpsymfonyfosrestbundle

Is there a way to create error with Fosrestbundle without using form and validation?


I mean creating an error 400, 500 generated by the ViewHandler of Fosrestbundle directly from the controller without using an Entity and a Form.


Solution

  • I don't know if i understood you question correctly but there are some possibilities.

    return $this->view(null, 400);
    

    You can return the view with the status code. In some cases i thow an HTTPException.

    use Symfony\Component\HttpKernel\Exception\HttpException;
    
    throw new HttpException(400, "Input not correct or not allowed!");
    

    There you can define the status code and the error message.