未找到路由,Symfony路由未正确更新

时间:2017-08-18 07:48:02

标签: php symfony symfony-routing

我的routing.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 / console debug:router

...
  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 cache:clear --env prod

在Windows 10上运行Xampp并使用phpStorm进行编辑。

我昨晚用api_reviews_遇到完全相同的问题,但不知怎的,它决定最终起作用。

1 个答案:

答案 0 :(得分:4)

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

所以试试这个:

class PutController
{
    public function putReviewsPutAction($id)
    {

而不是:

class PutController
{
    public function putReviewsPut($id)
    {

希望这个帮助