问题
I'm trying to override the base layout of FOSUserBundle using the 'simple' option of making a cloned path as .app/Resources/FOSUserBundle/views/layout.html.twig
, but symfony2.6 continues to render the template from inside the vendor directory.
My composer requires:
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.6.*",
"doctrine/orm": "~2.2,>=2.2.3,<2.5",
"doctrine/dbal": "<2.5",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0,>=3.0.12",
"sensio/framework-extra-bundle": "~3.0,>=3.0.2",
"incenteev/composer-parameter-handler": "~2.0",
"friendsofsymfony/user-bundle": "~1.3"
},
I've checked the following common issues:
- filesystem case sensitivity - looks OK
- having the correct path - seems OK
- clearing the cache: both manually and from the app/console - no problem here
Other information: - runs on a vagrant instance with ubuntu-trusty-64 - the synced folder is through NFS
Any ideas in what I should look or do next ?
回答1:
The problem had mostly nothing to do with Symfony2 or FOSUserBundle, but with the way PHP caches the file stats.
To locate the right template to load, standard Symfony2 uses Symfony\Component\HttpKernel\Kernel->locateResource
, by first checking if an override exists in the .app\Resources
directory and if the $first
parameter is set to true it returns from inside the foreach loop.
In my configuration, PHP decided to keep using the filecache and answer no to file_exists even if the file was there.
To go around / fix this problem my AppKernel.php
overrides the locateResource
of the Symfony\Component\HttpKernel\Kernel
class:
<?php
class AppKernel extends Kernel
{
// .. other methods here
public function locateResource($name, $dir = null, $first = true)
{
clearstatcache(true);
return parent::locateResource($name, $dir, $first);
}
}
Not pretty, but it works.
来源:https://stackoverflow.com/questions/30405308/what-is-the-issue-with-not-overriding-templates-in-symfony2-6-and-fosuserbundle