【问题标题】:What should be edited in routing.yml in symfony 3 to create a new route from annotation?在 symfony 3 的 routing.yml 中应该编辑什么来从注解创建新路由?
【发布时间】:2016-04-30 19:30:56
【问题描述】:

我对 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>

这给出了一个错误

"在渲染模板的过程中抛出了异常 (“无法为命名路由“patient_homepage”生成 URL 为 这样的路线不存在。") 在第 118 行的 base.html.twig 中。"

我还需要对app\config\routing.yml 进行任何更改吗?我在这里错过了什么。

【问题讨论】:

    标签: symfony symfony-routing


    【解决方案1】:

    试试这个

    应用程序:
        资源:“@AppBundle/Controller/”
        类型:注释

    【讨论】:

      【解决方案2】:

      你必须在app/config/routing.yml启用路由

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

      【讨论】:

        猜你喜欢
        • 2011-02-20
        • 2016-10-10
        • 1970-01-01
        • 2019-06-13
        • 1970-01-01
        • 2019-07-15
        • 2021-06-26
        • 1970-01-01
        • 2019-10-20
        相关资源
        最近更新 更多