当我在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>');
}
}