我试图用Symfony2创建一个"Hello“,它似乎是第一次运行,但是无论我做什么改变并保存控制器,前端都没有任何变化。
我的控制器就是这样的:
namespace Test\CalcBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
class CalcController {
public function indexAction($name) {
return new Response("<html><body>Hello " . $name . "!</body></html>");
}
}无论我如何更改这个文件,浏览器中都没有反映任何内容。这是一种缓存吗?如果是的话,我如何禁用它?浏览器没有缓存它,因为如果我更改url的最后一点,它会在页面上反映出来。
我正在我的开发环境中运行这个程序- Windows 8,PHP5.5.3 (XAMPP),Apache。
更新:对不起,忘记添加,我使用的是:
http://localhost/test/web/app_dev.php/Calc/nameUPDATE2: app/config/routing.yml:
test_calc:
resource: "@TestCalcBundle/Resources/config/routing.yml"
prefix: /src/Test/CalcBundle/Resources/config/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中。
发布于 2013-09-28 14:19:03
Symfony对web dir中的应用程序有两个访问点。
web/app.php (这是用于生产的缓存是活动的)web/app_dev.php (对于dev,当您更改诸如模板等内容时,缓存会发生变化)。将浏览器指向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);与SF2.3.4一起拥有的文件
使用SF2.3.*的项目需要Debug::enable();行,检查文件中是否存在行
https://stackoverflow.com/questions/19067903
复制相似问题