我是Symfony的新成员,我正在从事现有的项目。我已经用doctrine:generate:crud创建了crud,但应用程序返回了未找到的404页。我正在用debug:router和router:match调试它,一切都很好。
这是我的控制器
<?php
namespace AppBundle\Controller\Backend;
use AppBundle\Controller\BackendController;
use AppBundle\Entity\CsobApiUsers;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* CsobApiUsers controller.
*
* @Route("csobApiUsers")
*/
class CsobApiUsersController extends BackendController
{
/**
* Lists all csobApiUser entities.
*
* @Route("/", name="csobapiusers_index")
* @Method("GET")
*/
public function indexAction()
{
die(var_dump("x"));
$em = $this->getDoctrine()->getManager();
$csobApiUsers = $em->getRepository('AppBundle:CsobApiUsers')->findAll();
return $this->render('csobapiusers/index.html.twig', array(
'csobApiUsers' => $csobApiUsers,
));
}控制器与另一个正确工作的控制器相同。
这是我的路由器:match
php bin/console router:match /backend/csobApiUsers/
[OK] Route "csobapiusers_index" matches
+--------------+---------------------------------------------------------+
| Property | Value |
+--------------+---------------------------------------------------------+
| Route Name | csobapiusers_index |
| Path | /backend/csobApiUsers/ |
| Path Regex | #^/backend/csobApiUsers/$#s |
| Host | ANY |
| Host Regex | |
| Scheme | ANY |
| Method | GET |
| Requirements | NO CUSTOM |
| Class | Symfony\Component\Routing\Route |
| Defaults | _controller: AppBundle:Backend\CsobApiUsers:index |
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
+--------------+---------------------------------------------------------+下面是调试:用于我的控制器的路由器
csobapiusers_index GET ANY ANY /backend/csobApiUsers/
csobapiusers_new GET|POST ANY ANY /backend/csobApiUsers/new
csobapiusers_show GET ANY ANY /backend/csobApiUsers/{id}
csobapiusers_edit GET|POST ANY ANY /backend/csobApiUsers/{id}/edit
csobapiusers_delete DELETE ANY ANY /backend/csobApiUsers/{id}我打电话给
,有人知道哪里会有问题吗?谢谢
发布于 2020-11-24 11:00:05
我认为您在控制器路由注释中缺少斜杠,请查看这里的https://symfony.com/blog/new-in-symfony-3-4-prefix-all-controller-route-names
@Route("/csobApiUsers")发布于 2020-11-24 10:32:59
您是否尝试将indexAction()改为index()?
https://stackoverflow.com/questions/64984511
复制相似问题