【问题标题】:No route found, Symfony routing not updating properly找不到路由,Symfony 路由没有正确更新
【发布时间】:2018-01-26 19:44:04
【问题描述】:

我的路由.yml:

user_user:
    resource: "@UserUserBundle/Resources/config/routing.yml"
    prefix:   /user

book_book:
    resource: "@BookBookBundle/Resources/config/routing.yml"
    prefix:   /book

index_index:
    resource: "@IndexIndexBundle/Resources/config/routing.yml"
    prefix:   /


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

fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"

app_api:
    resource: "@AppBundle/Controller/Api"
    type:     annotation

mvms_api:
    type:     rest
    prefix:   /api
    resource: "@AppBundle/Resources/config/api-routing.yml"

我的

api-routing.yml:

blog_api_articles:
    type: rest
    resource: "@AppBundle/Controller/ArticlesController.php"
    name_prefix:  api_article_


blog_api_reviews:
    type: rest
    resource: "@AppBundle/Controller/ReviewsController.php"
    name_prefix:  api_reviews_


api_reviewsPut:
    type: rest
    resource: "@AppBundle/Controller/PutController.php"
    name_prefix:  api_put_

我的 php bin/控制台调试:路由器

...
  api_article_get_article             GET        ANY      ANY    /api/articles/{id}.{_format}
  api_reviews_get_review              GET        ANY      ANY    /api/reviews/{id}.{_format}

我的 api-routing 中的最后一个条目似乎没有工作/显示...

//This works fine
    class ReviewsController extends Controller
{

    /**
     * Note: here the name is important
     * get => the action is restricted to GET HTTP method
     * Article => (without s) generate /articles/SOMETHING
     * Action => standard things for symfony for a controller method which
     *           generate an output
     *
     * it generates so the route GET .../articles/{id}
     */
    public function getReviewAction($id)
    {

            $someId = $id;
            $rv = $this->getDoctrine()->getManager();
            $review = $rv->createQuery(
                'SELECT *  FROM AppBundle:Something r WHERE r.id= :id')->setParameter('id', $someId);

            $reviews = $review->getResult();
        if (empty($reviews)) {
            return array('Data' => 'none');
        }
        else
            return $reviews;
    }




}


class PutController
{
    public function putReviewsPut($id)
    {

        $someId = $id;
        $rv = $this->getDoctrine()->getManager();
        $review = $rv->createQuery(
            'some query')->setParameter('id', $someId);

        $reviews = $review->getResult();
        if (empty($reviews)) {
            return array('Data' => 'none');
        }
        else
            return $reviews;
    }
}

当我在 api-routing.yml 中输入新路由时,应用程序根本不会费心将它们考虑在内。 因此,我得到“找不到 \"GET /api/put/1\"”的路线, 在邮递员中

我尝试重新启动服务器 也试过 php bin/console 缓存:clear --env prod

在 Windows 10 上运行 Xampp 并使用 phpStorm 作为编辑器。

昨晚我在使用 api_reviews_ 时遇到了完全相同的问题,但不知何故它最终决定了。

【问题讨论】:

  • 你尝试清除缓存了吗?
  • @ImanaliMamadiev 是的
  • 它与复数有关...结尾处需要有一个 S。如果我理解了,我会详细说明

标签: php symfony symfony-routing


【解决方案1】:

您应该在控制器方法中使用后缀Action

所以试试这个:

class PutController
{
    public function putReviewsPutAction($id)
    {

而不是这个:

class PutController
{
    public function putReviewsPut($id)
    {

希望有帮助

【讨论】:

    猜你喜欢
    • 2017-12-29
    • 1970-01-01
    • 2016-07-03
    • 2020-07-29
    • 1970-01-01
    • 2017-01-01
    • 2015-04-14
    • 1970-01-01
    相关资源
    最近更新 更多