【发布时间】:2021-06-27 23:09:19
【问题描述】:
我在致电我的实体 Offer 时遇到问题 我想调用方法 getApplication() 但我收到了这个错误 无法猜测如何从参数“offer”的请求信息中获取 Doctrine 实例。 有人知道如何调用实体吗?谢谢
<?php
namespace App\Controller;
use App\Entity\Application;
use App\Entity\Offer;
use App\Repository\ApplicationRepository;
use App\Repository\BrandRepository;
use App\Repository\OfferRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
/**
* Class OfferController
* @package App\Controller
*
* @Route("/offer", name="offer_")
*/
class OfferController extends AbstractController
{
/**
* @Route("/", name="index")
*/
public function index(ApplicationRepository $applicationRepository, OfferRepository $offerRepository, Offer $offer)
{
$user = $this->getUser();
$offers = $offerRepository->findBy([], ['dateCreation' => 'DESC']);
$application = $applicationRepository->findOneBy(['id' => $offer->getApplication()]);
return $this->render('offer/index.html.twig', [
'offers' => $offers,
'application' => $application,
'offer' => $offer
]);
}
}
【问题讨论】:
-
您的路线
/offer/不包含Doctrine can use to infer 您要使用的实体的slug。也许重新配置你的路线可以解决这个问题?