不能用 symfony 2 运行控制器 [英] cant run the controller with symfony 2
问题描述
我用 netbeans 生成了我的包,没有错误,然后转到 app 目录中的主配置文件并设置:
I generated my bundle with netbeans with no error , then went to my main config file in the app directory and set this:
first_app:
resource: "@FirstAppBundle/Resources/config/routing.yml"
prefix: /
然后在我的 bundle routing.yml 文件中设置:
Then set this in my bundle routing.yml file:
first_app_homepage:
pattern: /hello/{name}
defaults: { _controller: FirstAppBundle:Hello:index }
我有这个控制器:
namespace DimaVendor\MytestsBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class HelloController extends Controller {
public function indexAction($name) {
return new Response('<html><body>' . $name . '</body></html>');
}
}
我去那里时收到 404:
I get 404 when I go to there:
http://localhost/app.php/hello/Ryan
为什么?
我也清理了缓存,没有发现错误
I also cleaned my cache and found no error
推荐答案
app.php
和 app_dev.php
脚本是 Symfony 应用程序的入口点,它们撒谎在项目的 web/
子文件夹中 - 在这种情况下,将浏览器指向:
app.php
and app_dev.php
scripts are the entry points for Symfony apps, and they lie in web/
subfolder in the project - in this case, point your browser to:
http://localhost/PhpProject1/web/app_dev.php/hello/Ryan
.htaccess
位于 web/
文件夹中,并将任何请求重定向到:
.htaccess
comes in web/
folder, and redirects any requests to:
http://localhost/PhpProject1/web/some/path
到:
http://localhost/PhpProject1/web/app.php/some/path
在你的情况下.看看!
这篇关于不能用 symfony 2 运行控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!