找不到路由,Symfony 路由没有正确更新
No route found, Symfony routing not updating properly
我的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_
我的phpbin/consoledebug:router
...
api_article_get_article GET ANY ANY /api/articles/{id}.{_format}
api_reviews_get_review GET ANY ANY /api/reviews/{id}.{_format}
我的 api-路由中的最后一个条目似乎不是 working/showing ...
//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 中输入新路线时,应用程序根本懒得考虑它们。
因此我得到 "No route found for \"GET /api/put/1\"",
在邮递员中
我试过重启服务器
也尝试过
php bin/console cache:clear --env 产品
运行 Xampp 在 Windows 10 上使用 phpStorm 作为编辑器。
我昨晚遇到了与 api_reviews_ 完全相同的问题,但不知何故它最终决定工作。
您应该在控制器方法中使用后缀Action
。
所以试试这个:
class PutController
{
public function putReviewsPutAction($id)
{
而不是这个:
class PutController
{
public function putReviewsPut($id)
{
希望对您有所帮助
我的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_
我的phpbin/consoledebug:router
...
api_article_get_article GET ANY ANY /api/articles/{id}.{_format}
api_reviews_get_review GET ANY ANY /api/reviews/{id}.{_format}
我的 api-路由中的最后一个条目似乎不是 working/showing ...
//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 中输入新路线时,应用程序根本懒得考虑它们。 因此我得到 "No route found for \"GET /api/put/1\"", 在邮递员中
我试过重启服务器 也尝试过 php bin/console cache:clear --env 产品
运行 Xampp 在 Windows 10 上使用 phpStorm 作为编辑器。
我昨晚遇到了与 api_reviews_ 完全相同的问题,但不知何故它最终决定工作。
您应该在控制器方法中使用后缀Action
。
所以试试这个:
class PutController
{
public function putReviewsPutAction($id)
{
而不是这个:
class PutController
{
public function putReviewsPut($id)
{
希望对您有所帮助