X-Plosion
X-Plosion

Reputation: 1

Symfony2 - Access dev cache without using the front controlleur app_dev.php

I have a question for you, I didn't manage to find any answers on the web : I would like to know if there is a way to access the dev cache (not the prod one) by using the front controller app.php instead of app_dev.php?

I need this for an administration interface, on which it's possible to edit translations with AJAX as if you are on the public page (same design, but you can edit translations by clicking on the text), the problem is that if I don't use app_dev.php, and I reload the page, Twig get the translations from the prod cache, so the old ones. Of course the interface is not for me but for somebody who don't know anything about programming, so I would like it to be transparent for him, that he just have to access the admin page, to login, and directly be on the dev cache.

I tried to edit app.php, by mixing it with app_dev.php depending of the URL, but Symfony don't like what I'm doing and send me some errors (It's possible that I do wrong what I want to do also :p ). Here is my app.php code:

use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;

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

require_once __DIR__.'/../app/AppKernel.php';

$path = explode('/', $_SERVER['PATH_INFO']);
if($path[1] == 'admin') // The URL to access the administration interface is something like http://www.mywebsite.com/admin[/...]
{
    Debug::enable();
    $kernel = new AppKernel('dev', true);
}
else
{
    $kernel = new AppKernel('prod', false);
}

$kernel->loadClassCache();
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

Maybe there are others types of solutions, I have sometimes seen some people on forums accessing directly to the cache with a method in the controller of their bundle, but I don't know how they do that and how to use it. I'm open to every proposal! =D

Thanks!

Adrien

Upvotes: 0

Views: 164

Answers (1)

Wouter J
Wouter J

Reputation: 41934

Never use dev cache in production, it'll slow down your app significantly. You simply have to rebuild the cache each time the admin saves changes.

Upvotes: 1

Related Questions