Symfony 2在路由时返回错误

时间:2016-10-22 13:03:44

标签: php symfony

当我在Symfony 2中添加新路由时,我收到错误:

  

控制器必须返回响应(给定null)。您是否忘记在控制器中的某处添加return语句?

文件routing.yml的内容是:

acme_hello:
    resource: "@AcmeHelloBundle/Resources/config/routing.yml"
    prefix:   /

app:
    resource: "@AppBundle/Controller/"
    type:     annotation

blog_show:
    path:      /blog/{slug}
    defaults:  { _controller: AppBundle:Blog:show }

档案/src/AppBundle/Controller/DefaultController.php

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */
    public function indexAction(Request $request)
    {
        // replace this example code with whatever you need
        return $this->render('default/index.html.twig', array(
            'base_dir' => realpath($this->container->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
        ));
    }

    public function indexAction2($page)
    {
        //$number = 2;
        print "dobrze";
        //return "dobrze";
        //return $response = new Response('Page not found.',   Response::HTTP_NOT_FOUND);
        //$this->render ('<html><body>Lucky number: '.$number.'</body></html>');
    }
}

1 个答案:

答案 0 :(得分:0)

我认为你应该首先阅读文档,特别是“入门”一章

http://symfony.com/doc/current/index.html

祝你好运; - )