我试图创建一个" Hello World"使用Symfony2它似乎第一次运行,但无论我做什么改变并保存控制器 - 前端都没有任何变化。
这就是我的控制器的样子:
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。
更新抱歉,忘了添加,我使用的网址是:
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而不是我创建的那个...我该如何解决?
UPDATE5:我设法解决了这个问题,虽然我不知道这是否是一个很好的方法。我已将src/Test/CalcBundle/Resources/config/routing.yml
更改为如下所示:
test_calc_homepage:
pattern: /Calc/{name}
defaults: { _controller: TestCalcBundle:Calc:index }
UPDATE6:已解决 - 由于缺乏理解,问题是routing.yml中的默认控制器。
答案 0 :(得分:0)
Symfony在web dir中有两个访问应用程序的访问点
web/app.php
(这是用于生产缓存处于活动状态)web/app_dev.php
(这是因为当您更改模板等内容时,缓存会发生变化。)将浏览器指向http://localhost/app_dev.php
您可以在Creating Pages in 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();
行,检查文件中是否存在该行