我正在开发一个使用Visual代码和Intelephense的Symfony 4项目。
Intelephense得到的错误不是。有一些例子:
未定义的方法'uasort‘。
此错误对应于此代码:
// Collection creation of seasons used in the periods
$seasons = new ArrayCollection();
$sortedSeasons = new ArrayCollection();
//Search seasons used by periods
foreach ($advert->getPeriods() as $period)
{
$season = $period->getSeason();
if (! $seasons->contains($season))
{
$seasons->add($season);
}
}
// Sort seasons by ascending cost
$iterator = $seasons->getIterator();
$iterator->uasort(function ($a, $b) {
return $a->getCost() <=> $b->getCost();
});另一个例子是:
未定义的方法'getAdvertMinPrice‘
$minPrices = $this->getDoctrine()->getRepository(Price::class)->getAdvertMinPrice($advert);但是,该方法存在于PriceRepository中:
<?php
namespace App\Repository\advert;
use App\Entity\advert\Price;
use Symfony\Bridge\Doctrine\RegistryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
/**
* @method Price|null find($id, $lockMode = null, $lockVersion = null)
* @method Price|null findOneBy(array $criteria, array $orderBy = null)
* @method Price[] findAll()
* @method Price[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PriceRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Price::class);
}
/**
* Get the minimum price from an advert
*
* @param [type] $advert
* @return Price[]
*/
public function getAdvertMinPrice($advert): array
{
return $this->createQueryBuilder('p')
->andWhere('p.price = (
SELECT MIN(p2.price)
FROM ' . $this->_entityName . ' p2
WHERE p2.advert = :val
)'
)
->setParameter('val', $advert)
->getQuery()
->getResult()
;
}
}这里有价格名称空间:
<?php
namespace App\Entity\advert;
use App\Entity\advert\Advert;
use App\Entity\advert\Period;
use App\Entity\backend\Season;
use App\Entity\backend\Duration;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass="App\Repository\advert\PriceRepository")
*
* @UniqueEntity(
* fields={"duration", "season"},
* message="A price already exists for this season and this duration."
* )
*/
class Price
{以及我遇到问题的文件中的use命令:
<?php
namespace App\Controller\advert;
use App\Entity\backend\VAT;
use App\Entity\advert\Price;我不明白问题在哪里。我找了好几天都没有结果。
有人会想到这个问题的根源吗?
发布于 2019-12-27 12:06:31
通过卸载和重新安装Visual代码扩展来解决问题。
发布于 2020-04-22 14:08:03
简单地重新加载窗口(VSCode)通常可以解决这个问题。那么不需要重新安装扩展程序。
要重新加载vscode,请打开命令调色板(F1)并选择Developer: Reload Window。这等于重新启动编辑器。
发布于 2020-11-24 05:59:22
我已经找到了解决办法:
下面是我的一个项目的代码:
/** @var ActivityRepository */
$activityRepo = $this->getDoctrine()->getRepository(Activity::class);
return $this->json($activityRepo->search($searchData['text']));我的"->search“给了我错误,然后在变量上添加了PHPDoc注释:
/** @var ActivityRepository */
现在起作用了!
还可以看看这个:
https://stackoverflow.com/questions/59444350
复制相似问题