Symfony2 - Twig 更新未呈现
Symfony2 - Twig updates are not rendering
我是 Symfony2 的初学者。我已经创建了我的第一个模板,我可以通过 URL http://localhost/mylibrary-web/web/app_dev.php/hello/Test.
访问它
这是我的 src/MyLibrary/LibraryBundle/Resources/views/Default/index.html.twig
文件的内容:
Hello {{ name }}!
我没有 工具栏 (因为我没有 </body>
元素,但是如果我用 :
<html>
<body>
Hi {{ name }}!
</body>
</html>
没有任何变化。不考虑这些修改。当我调用 URL http://localhost/mylibrary-web/web/app_dev.php/hello/Test.
时仍然显示旧内容
我尝试用命令行php app\console cache:clear
清除缓存。我还尝试通过删除 app\cache
目录来硬删除缓存。最后,我尝试将以下行添加到 config_dev.yml
文件中:
twig:
cache: false
很遗憾,没有任何变化,我仍然显示旧内容。
我是否缺少更新 twig 文件的内容?
提前感谢您的帮助!
编辑:
这里是 src/MyLibrary\LibraryBundle\Controller\DefaultController.php
文件的代码:
<?php
namespace MyLibrary\LibraryBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function indexAction($name)
{
return $this->render('MyLibraryLibraryBundle:Default:index.html.twig', array('name' => $name));
}
}
和命令行的结果php app\console route:debug
:
[router] Current routes
Name Method Scheme Host Path
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_purge ANY ANY ANY /_profiler/purge
_profiler_info ANY ANY ANY /_profiler/info/{about}
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
_configurator_home ANY ANY ANY /_configurator/
_configurator_step ANY ANY ANY /_configurator/step/{index}
_configurator_final ANY ANY ANY /_configurator/final
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
my_library_library_homepage ANY ANY ANY /hello/{name}
homepage ANY ANY ANY /app/example
编辑 2:
这里是my_library_library_homepage路由的定义:
my_library_library_homepage:
path: /hello/{name}
defaults: { _controller: MyLibraryLibraryBundle:Default:index }
这里是我 grep Hello {{ name }}!
时的结果:
- C:\wamp\www\mylibrary-web\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Resources\skeleton\acme-demo-bundle\Acme\DemoBundle\Resources\views\Demo\hello.html.twig
- C:\wamp\www\mylibrary-web\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Resources\skeleton\acme-demo-bundle\Acme\DemoBundle\Resources\views\Secured\hello.html.twig
- C:\wamp\www\mylibrary-web\vendor\sensio\generator-bundle\Sensio\Bundle\GeneratorBundle\Tests\Generator\BundleGeneratorTest.php
- C:\wamp\www\mylibrary-web\vendor\twig\extensions\doc\i18n.第一个
- C:\wamp\www\mylibrary-web\vendor\twig\twig\doc\api.第一个
- C:\wamp\www\mylibrary-web\vendor\twig\twig\doc\intro.第一个
首先,检查您是否有写入文件夹缓存的权限:
app/cache/dev/
删除那里的所有文件 运行:
php app/console cache:clear --env=dev
php app/console cache:warmup --env=dev
这可能很奇怪但是...重新启动 wamp 服务后,一切似乎都正常...
我是 Symfony2 的初学者。我已经创建了我的第一个模板,我可以通过 URL http://localhost/mylibrary-web/web/app_dev.php/hello/Test.
访问它这是我的 src/MyLibrary/LibraryBundle/Resources/views/Default/index.html.twig
文件的内容:
Hello {{ name }}!
我没有 工具栏 (因为我没有 </body>
元素,但是如果我用 :
<html>
<body>
Hi {{ name }}!
</body>
</html>
没有任何变化。不考虑这些修改。当我调用 URL http://localhost/mylibrary-web/web/app_dev.php/hello/Test.
时仍然显示旧内容我尝试用命令行php app\console cache:clear
清除缓存。我还尝试通过删除 app\cache
目录来硬删除缓存。最后,我尝试将以下行添加到 config_dev.yml
文件中:
twig:
cache: false
很遗憾,没有任何变化,我仍然显示旧内容。
我是否缺少更新 twig 文件的内容?
提前感谢您的帮助!
编辑:
这里是 src/MyLibrary\LibraryBundle\Controller\DefaultController.php
文件的代码:
<?php
namespace MyLibrary\LibraryBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function indexAction($name)
{
return $this->render('MyLibraryLibraryBundle:Default:index.html.twig', array('name' => $name));
}
}
和命令行的结果php app\console route:debug
:
[router] Current routes
Name Method Scheme Host Path
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_purge ANY ANY ANY /_profiler/purge
_profiler_info ANY ANY ANY /_profiler/info/{about}
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
_configurator_home ANY ANY ANY /_configurator/
_configurator_step ANY ANY ANY /_configurator/step/{index}
_configurator_final ANY ANY ANY /_configurator/final
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
my_library_library_homepage ANY ANY ANY /hello/{name}
homepage ANY ANY ANY /app/example
编辑 2:
这里是my_library_library_homepage路由的定义:
my_library_library_homepage:
path: /hello/{name}
defaults: { _controller: MyLibraryLibraryBundle:Default:index }
这里是我 grep Hello {{ name }}!
时的结果:
- C:\wamp\www\mylibrary-web\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Resources\skeleton\acme-demo-bundle\Acme\DemoBundle\Resources\views\Demo\hello.html.twig
- C:\wamp\www\mylibrary-web\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Resources\skeleton\acme-demo-bundle\Acme\DemoBundle\Resources\views\Secured\hello.html.twig
- C:\wamp\www\mylibrary-web\vendor\sensio\generator-bundle\Sensio\Bundle\GeneratorBundle\Tests\Generator\BundleGeneratorTest.php
- C:\wamp\www\mylibrary-web\vendor\twig\extensions\doc\i18n.第一个
- C:\wamp\www\mylibrary-web\vendor\twig\twig\doc\api.第一个
- C:\wamp\www\mylibrary-web\vendor\twig\twig\doc\intro.第一个
首先,检查您是否有写入文件夹缓存的权限:
app/cache/dev/
删除那里的所有文件 运行:
php app/console cache:clear --env=dev
php app/console cache:warmup --env=dev
这可能很奇怪但是...重新启动 wamp 服务后,一切似乎都正常...