首页 文章

应该在symfony 3中的routing.yml中编辑什么来从注释创建新路由?

提问于
浏览
0

我是Symfony 3的新手 . 我在AppBundle中创建了控制器文件 . 没有创建新的包 . 现在我正在尝试路由新页面,但它会出错 . 这就是我做的 .

src\AppBundle\Controller\Patient\PatientController.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("/patient", name="patient_homepage")
    */
    public function patientHomeAction(Request $request)
    {
        // replace this example code with whatever you need
        return $this->render('Patient/home.html.twig', array()
        );
    }

app\Resources\views\base.html.twig

<a href="{{ path('patient_homepage') }}">Home</a>

这给出了一个错误

“在渲染模板期间抛出异常(”无法生成指定路径的URL“patient_homepage”,因为这样的路线不存在 . “)在第118行的base.html.twig中 . ”

我是否还需要对_2989952进行任何更改?我在这里想念的是什么

2 回答

  • 1

    试试这个

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

    您必须在 app/config/routing.yml 中启用路线

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

相关问题