0

I'm using the symfony component "HttpFoundation", and I'm trying to implement RESTful routing. But I can't perform an update, it's like the route does not exist while it did, here's my routes file :

TaskHome:
    pattern: /tasks
    defaults: { controller: 'ModuleToDoList\Controllers\TaskController', action: 'indexAction' }
    requirements:
        _method: GET

TaskCreate:
    pattern: /tasks/create
    defaults: { controller: 'ModuleToDoList\Controllers\TaskController', action: 'createAction' }
    requirements:
        _method: GET

TaskStore:
    pattern: /tasks
    defaults: { controller: 'ModuleToDoList\Controllers\TaskController', action: 'storeAction' }
    requirements:
        _method: POST

TaskShow:
    pattern: /tasks/{id}
    defaults: { controller: 'ModuleToDoList\Controllers\TaskController', action: 'showAction' }
    requirements:
        _method: GET

TaskEdit:
    pattern: /tasks/{id}/edit
    defaults: { controller: 'ModuleToDoList\Controllers\TaskController', action: 'editAction' }
    requirements:
        _method: GET

TaskUpdate:
    pattern: /tasks/{id}
    defaults: { controller: 'ModuleToDoList\Controllers\TaskController', action: 'updateAction' }
    requirements:
        _method: PUT

TaskDestroy:
    pattern: /tasks/{id}
    defaults: { controller: 'ModuleToDoList\Controllers\TaskController', action: 'destroyAction' }
    requirements:
        _method: DELETE

and here's my form :

<form method="post" action="{{ route('TaskUpdate', {'id': task.id}) }}">
    <input type="hidden" name="_method" value="PUT">
    <div class="well-inner form-horizontal">
        <fieldset>
            <legend>Edit a task</legend>
            <div>
                <label for="title">Title: </label>
                <input type="text" name="title" value="{{ task.title }}">
            </div>
            <div>
                <label for="description">Description : </label>
                <input type="text" name="description" value="{{ task.description }}">
            </div>
            <div>
                <label for="priority">Priority: </label>
                <input type="text" name="priority" value="{{ task.priority }}">
            </div>
            <div>
                <input type="submit" value="Save" class="btn btn-primary">
            </div>
        </fieldset>

    </div>
</form>

When I hit save, it redirects me to the 404 page.

teeyo
  • 3,665
  • 3
  • 22
  • 37
  • are other routes working correctly? – xurshid29 Nov 05 '14 at 14:55
  • @xurshid29 Only post and get, I added the line `Request::enableHttpMethodParameterOverride();` so HttpFoundation will override the method with the _method parameter, but no luck. – teeyo Nov 05 '14 at 15:01
  • I've never tried REST UPDATE method with HTML form, that's why I 'm not very sure if `
    – xurshid29 Nov 05 '14 at 15:07
  • @xurshid29 the method will be overritten only if the default `method` is a `post`. it's written in the doc : `The HTTP method can only be overridden when the real HTTP method is POST.` http://api.symfony.com/2.3/Symfony/Component/HttpFoundation/Request.html#method_enableHttpMethodParameterOverride – teeyo Nov 05 '14 at 15:20

0 Answers0