在Windows上安装Symfony 2

时间:2015-07-05 06:17:02

标签: php symfony

我正在尝试在Windows 8.1上安装Symfony 2。 我使用wampp服务器作为我的本地主机。

首先,我使用此命令来下载symfony文件:

php -r "readfile('http://symfony.com/installer');" > symfony

比我用过:

php symfony

之后我创建了一个项目:

php symfony new my_project

比我用这个命令运行:

php app/console server:run

它成功运行但我访问时http://localhost:8000/。它会打开一个带有此错误的交响乐页面:

 No route found for "GET /"
404 Not Found - NotFoundHttpException
1 linked Exception:

    ResourceNotFoundException »

[2/2] NotFoundHttpException: No route found for "GET /"  +
[1/2] ResourceNotFoundException:   +
Logs  -
1 error

    ERROR - Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /"" at D:\Coding\www\my_project\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php line 159
    DEBUG - Notified event "kernel.request" to listener "Symfony\Component\EventDispatcher\Debug\WrappedListener::__invoke".
    DEBUG - Notified event "kernel.request" to listener "Symfony\Component\EventDispatcher\Debug\WrappedListener::__invoke".
    DEBUG - Notified event "kernel.request" to listener "Symfony\Component\EventDispatcher\Debug\WrappedListener::__invoke".
    DEBUG - Notified event "kernel.request" to listener "Symfony\Component\EventDispatcher\Debug\WrappedListener::__invoke".
    DEBUG - Notified event "kernel.request" to listener "Symfony\Component\EventDispatcher\Debug\WrappedListener::__invoke".
    DEBUG - Notified event "kernel.request" to listener "Symfony\Component\EventDispatcher\Debug\WrappedListener::__invoke".
    DEBUG - Notified event "kernel.request" to listener "Symfony\Component\EventDispatcher\Debug\WrappedListener::__invoke".
    DEBUG - Notified event "kernel.request" to listener "Symfony\Component\EventDispatcher\Debug\WrappedListener::__invoke".
    DEBUG - Notified event "kernel.request" to listener "Symfony\Component\EventDispatcher\Debug\WrappedListener::__invoke".
    DEBUG - Notified event "kernel.request" to listener "Symfony\Component\EventDispatcher\Debug\WrappedListener::__invoke".
    DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController".
    DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController".
    DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController".
    DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController".
    DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController".
    DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController".
    DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".

Stack Trace (Plain Text)  + 

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

这是一个正常的消息,因为在安装symfony2的默认版本后,它没有定义任何路由。

首先尝试http://localhost:8000/app_dev.php/而不是http://localhost:8000/

您还可以创建一个具有默认路由的控制器,以便能够检查一切是否正常。

// src/AppBundle/Controller/MainController.php

// ...
class MainController extends Controller
{
    /**
     * @Route("/")
     */
    public function homepageAction()
    {
die ("Everythig works fine");
        return true;
    }
}

此外,这可能是因为您的演示路线等于/ app / example或类似的东西。转到AppBundle中的DefaultController并将@Route参数更改为单斜杠/

https://symfony.com/doc/current/book/routing.html