[英]Symfony2 caching issue
我正在尝试使用Symfony2创建一个“Hello World”,它似乎第一次运行,但无论我做什么改变并保存控制器 - 前端都没有任何变化。
这就是我的控制器的样子:
namespace Test\CalcBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
class CalcController {
public function indexAction($name) {
return new Response("<html><body>Hello " . $name . "!</body></html>");
}
}
无论我如何更改此文件 - 浏览器中都没有反映出来。 这是某种缓存,如果是这样,我如何禁用它? 浏览器没有缓存它,因为如果我更改了网址的最后一位 - 它会反映在页面上。
我在我的开发环境中运行它 - Windows 8,PHP 5.5.3(XAMPP),Apache。
更新:抱歉,忘了添加,我正在使用的URL是:
http://localhost/test/web/app_dev.php/Calc/name
UPDATE2: app / config / routing.yml:
test_calc:
resource: "@TestCalcBundle/Resources/config/routing.yml"
prefix: /
SRC /测试/ CalcBundle /资源/配置/ routing.yml中:
test_calc_homepage:
pattern: /Calc/{name}
defaults: { _controller: TestCalcBundle:Default:index }
UPDATE3:我使用的Symfony2的确切版本是2.3.5
UPDATE4:找到原因 - 不知怎的,正在使用DefaultController而不是我创建的那个......我该如何解决这个问题?
更新5:我设法解决了这个问题,虽然我不知道这是否是一个很好的方法。 我已将src/Test/CalcBundle/Resources/config/routing.yml
更改为如下所示:
test_calc_homepage:
pattern: /Calc/{name}
defaults: { _controller: TestCalcBundle:Calc:index }
UPDATE6:已解决 - 由于缺乏理解,问题是routing.yml中的默认控制器。
Symfony在web目录中有两个应用程序访问点
web/app.php
(这是用于生产缓存是活动的) web/app_dev.php
(这是为了在您更改模板等内容时更改缓存更改) 将浏览器指向http://localhost/app_dev.php
您可以在Symfony 2中创建页面中获取有关环境的更多信息
你可以检查你的文件是否正确
app.php
<?php
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key conflicts
// with other applications also using APC.
/*
$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);
*/
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
app_dev.php
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
这些文件与sf 2.3.4有关
sf 2.3。*的项目需要Debug::enable();
,检查文件中是否存在该行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.