[英]Symfony2 - to see changes in twig have to clear cache every-time
我现在才有这个问题。 每当我改变我的树枝时,我都要cache:clear
。 如果代码中出现错误,是否显示错误? 我该怎么办?!
我多次遇到过这个问题。 如果您的网站被这么多用户访问并清除了缓存。 我确定你的网站已经关闭几分钟,直到新缓存生成。
因此,生产服务器上的清除缓存不应该是常规活动。 从这个问题中可以克服几种解决方案或技巧:
如何清除缓存
php app/console cache:clear
chmod -R 777 app/cache
chmod -R 777 app/logs
替代
您必须在位于Web文件夹中的app.php文件中进行一些更改。
更改
$kernel = new AppKernel('prod', false);
至
$kernel = new AppKernel('prod', true);
并清除缓存
我刚刚创建了一个控制台命令来有选择地手动列出或删除twig缓存文件,而不是运行耗时的clear:cache来清除所有内容。 语法是:
kmlf:twig --clear --env = dev AcmeBundle :: nglayout.html.twig AcmeBundle:Simple:simple3.html.twig
如果您只想列出缓存文件位置,可以删除--clear标志。 它似乎在Symfony 2.3的prod和dev环境中运行良好:
use Symfony\Component\Console\Command\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
class TwigCacheCommand extends ContainerAwareCommand
{
public function configure()
{
$this->setName('kmlf:twig')
->setDescription('selectively manage the twig cache')
->addArgument(
'names',
InputArgument::IS_ARRAY,
'Example AcmeBundle:Section:view.html.twig',
null
)->addOption('clear','c', InputOption::VALUE_NONE, 'delete cache files' );
}
public function write($output, $text) {
$output->writeln($text);
}
public function execute(InputInterface $input, OutputInterface $output)
{
$environment = $this->getContainer()->get('twig');
$names = $input->getArgument('names');
$actionName = null;
if ($input->getOption('clear')) {
$actionName = 'deleting';
$action = function ($fileName) {
unlink($fileName);
};
} else {
$actionName="path:";
$action = function ($filename) {
};
}
foreach ($names as $name) {
$fileName = $environment->getCacheFilename($name);
if (file_exists($fileName)) {
$action($fileName);
} else {
$fileName = 'not found.';
}
$this->write($output, $actionName.' '.$name."\ncacheFile: ".$fileName);
}
$this->write($output, 'Done');
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.