Cómo recargar la memoria caché de twig en symfony2


Soy nuevo en PHP , tengo una aplicación desarrollada en PHP y symfony2 framework. He cambiado el archivo html, el cambio no se refleja cuando estoy actualizando la página.

01. I restarted the server No luck.

02. I tried to remove the twig folder from /protected/cache/ page it self not loading.

Amablemente aconsejo , estoy usando el servidor tomcat para implementar.

Nota: No tengo la línea de comandos symfony2 configurada en el servidor.

Author: Azhar, 2013-05-05

7 answers

La forma más sencilla, escriba el comando :

rm -rf app/cache/*

El punto es: todos los archivos en app/cache/ se pueden eliminar libremente, se regeneran cuando sea necesario.

Si realmente quieres borrar solo la memoria caché de twig :

rm -rf app/cache/<environment>/twig

Sustitúyase <environment> por dev, prod, o test según sus requisitos.

 38
Author: Alain Tiemblo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-05-05 20:26:08

Al crear una nueva instancia Twig_Environment, puede pasar una matriz de opciones como segundo argumento del constructor. Uno de ellos es auto_reload. Cuando se desarrolla con Twig, es útil recompilar la plantilla cada vez que cambia el código fuente. Si no proporciona un valor para la opción auto_reload, se determinará automáticamente en función del valor debug.

Establece auto_reload como true:

$twig = new Twig_Environment($loader, array('auto_reload' => true));

Documentación de Twig para desarrollador: http://twig.sensiolabs.org/doc/api.html#environment-options

 30
Author: Link,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-23 06:07:25

Tuve un problema similar, pero eliminar la carpeta caché no tuvo ningún impacto en mi plantilla y no se por qué. Lo que parece resolver mi problema ahora es el siguiente código en mi config_dev.yml:

twig:
    cache: false

Tal vez esto también sea una solución para usted, por lo que no necesita usar el comando todo el tiempo.

Referencias:

Configuración de TwigBundle

Opciones de entorno Twig

 12
Author: Manuel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-08 09:17:30

Si está utilizando opcache/otro almacenamiento en caché similar, eliminar la carpeta de caché de twig no actualizará las plantillas, ya que la caché de twig solo consiste en .archivos php. Necesita eliminar la carpeta de caché de twig + ejecutar el archivo php que contiene:

Opcache_reset();

 3
Author: j4r3k,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-19 08:38:06

Tienes que hacer algunos cambios en la aplicación.archivo php ubicado en la carpeta web.

Cambio:

$kernel = new AppKernel('prod', false);    

A:

$kernel = new AppKernel('prod', true);

Y borra la caché si quieres.

 2
Author: Abdelghafour Ennahid,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-28 15:33:59

Puede agregar una función como esta:

public function renderView($view, array $parameters = array())
{
    $loader = new \Twig_Loader_Filesystem($this->container->getParameter("template_path"));
    $twig = new \Twig_Environment($loader, array('auto_reload' => true,
        'cache' => false
    ));

    /////////////////////add a translate filter/////////////////////// 
    $getTextdomain = new \Twig_SimpleFilter('trans',function ($string){
        return $this->container->get('translator')->trans($string);
    });

    $twig->addFilter($getTextdomain);
    //////////////////////////////////////////////////////////////////

    ///////////////////////////Add an extension twig//////////////////
    $twig->addExtension(new Extension());
    //////////////////////////////////////////////////////////////////

    return $twig->render($view, $parameters);
}
 0
Author: Themer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-30 16:48:33

Si está utilizando OPcache, asegúrese de comentar opcache.validate_timestamps=0 en el entorno dev.

 0
Author: Nkoyan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-15 22:34:42