Question

I'm using Symfony2 and I have a ReaderBundle that has an Rss entity.

I'm created CRUD for this entity.

php app/console generate:doctrine:crud --entity=RSSReaderBundle:Rss --format=annotation --with-write

All was well, before I connected Cache.

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppCache.php';
require_once __DIR__.'/../app/AppKernel.php';

Debug::enable();

$kernel = new AppKernel('dev' , true);
$kernel->loadClassCache();
$kernel = new AppCache($kernel); // THAT STRING IS MAIN PROBLEM
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

And then when i'm trying to delete some record, i take this error:

No route found for "POST /rss/delete/30": Method Not Allowed (Allow: DELETE)
405 Method Not Allowed

I created a form that clearly indicates the method:


private function createDeleteForm($id)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('rss_delete', array('id' => $id)))
            ->setMethod("DELETE")
            ->add('submit', 'submit', array('label' => 'Delete'))
            ->getForm()
        ;
    }

I have not found the problem. Help please

Was it helpful?

Solution 3

we must remove the string with comment "THAT STRING IS MAIN PROBLEM". Cache is working all the same. And CRUD working right

OTHER TIPS

This problem occurred since symfony2.2, see https://github.com/symfony/symfony-standard/commit/1970b831f8843a5cf551e9d88404cb62f21b90f9

You need to modify the Symfony\Component\HttpFoundation\Request::$httpMethodParameterOverride boolean manually in your app.php file:

// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
Request::enableHttpMethodParameterOverride();

There is no method="DELETE" in html forms ... at least not supported in almost all browsers - only in ajax requests.

Work around this by allowing DELETE and POST requests to the route.

I have the same problem that you had (with PUT and DELETE HTTP method) but I don't understand your solution.

Did you:
a) just get rid of // THAT STRING IS MAIN PROBLEM
or
b) get rid of $kernel = new AppCache($kernel); // THAT STRING IS MAIN PROBLEM

The solution b) is the same as not using cache so in my case, it's not helping as the page take a very long time to load.

@Nifr: I thought there were method PUT and DELETE. I use them in my forms following the instructions on this link: http://symfony.com/fr/doc/current/cookbook/routing/method_parameters.html So in fact, Symfony2 is able to tell whether a method is PUT, DELETE, POST or GET. But somehow, the cache can't...

Any help on that?

Edit: I found a solution that doesn't involve changing anything in the app.php file. Basically, the problem comes from the fact that the getMethod method of the request object of symfony2 doesn't know about PUT or DELETE method. The point is to change that in the AppCache.php file.

We just have to override the method invalidate of the AppCache.php file:

protected function invalidate(Request $request, $catch = false)
{
  $request->setMethod($request->request->get('_method'));
  return parent::invalidate($request, $catch);
}

Here, I just change the method of the request by the method posted from the form.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top