2017-10-06 58 views
0

我有問題,當我嘗試使用路線。它不能被生成,我通過/app/config/routes.xml嘗試,但是當我修改我得到錯誤,該文件不是YAML格式。Symfony 3.3.10路線

控制器看起來:

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

    class MainController extends Controller 
    { 
    public function indexAction(Request $request) 
    { 
    return $this->render('main/index.html.twig', [ 
     'base_dir' => realpath($this->getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR, 
    ]); 
} 
} 

當我試圖訪問/索引或主/索引它給我的路線不存在! :@

當我放置使用Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ Route;首先在Controller之前。

回答

0
  • 首先,您必須將名稱空間放在標題上。

  • 其次在Symfony 3.3.10中您要使用哪條路徑必須在public function indexAction之前聲明。

所以,你的路線聲明將如下所示:

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

class MainController extends Controller 
{ 
    /** 
    *@Route("visit/index") 
    */ 
    public function indexAction(Request $request) 
    { 


     return $this->render('main/index.html.twig', ['base_dir' => realpath($this->getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR,]); 

    } 
}