Php 找不到搜索方法的常量名称
我创建了一个搜索方法,该方法应允许我在细枝表中搜索,添加了自定义存储库方法,该方法允许我通过指定属性查找实体,并在控制器函数中调用它,以及负责搜索函数的脚本,其输入标签在细枝文件中,但我一直得到“[语义错误]在C:\Users\maiez\Projet\config/routes.././src/Controller/(从“C:\Users\maiez\Projet\config/routes/annotations.yaml”导入)中找不到常量名称、方法App\Controller\InventaireContesController::searchConte()。请确保已安装并启用批注。 “错误。 请在包含搜索功能的细枝代码中找到以下脚本:Php 找不到搜索方法的常量名称,php,symfony,search,twig,repository,Php,Symfony,Search,Twig,Repository,我创建了一个搜索方法,该方法应允许我在细枝表中搜索,添加了自定义存储库方法,该方法允许我通过指定属性查找实体,并在控制器函数中调用它,以及负责搜索函数的脚本,其输入标签在细枝文件中,但我一直得到“[语义错误]在C:\Users\maiez\Projet\config/routes.././src/Controller/(从“C:\Users\maiez\Projet\config/routes/annotations.yaml”导入)中找不到常量名称、方法App\Controller\Inven
<script>
$(document).ready(function(){
$('#search').keyup(function(){
search_table($(this).val());
});
function search_table(value){
$('#sa tbody').each(function(){
var found = 'false';
$(this).each(function(){
if($(this).text().toLowerCase().indexOf(value.toLowerCase()) >= 0)
{
found = 'true';
}
});
if(found == 'true')
{
$(this).show();
}
else
{
$(this).hide();
}
});
}
});
</script>
这是控制器方法,似乎不起作用:
/**
* @Route ("/invContes/search", name"searchInv")
* @param Request $request
* @param NormalizerInterface $Normalizer
* @return Response
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
*/
public function searchConte(Request $request, NormalizerInterface $Normalizer)
{
$repository = $this->getDoctrine()->getRepository(Inventairecontes::class);
$requestString=$request->get('searchValue');
$conte=$repository->findContes($requestString);
$jsonContent=$Normalizer->normalize($conte,'json',['groups'=>'contes']);
$retour = json_encode($jsonContent);
return new JsonResponse($jsonContent);
}
导入和细枝ID是正确的。
提前感谢。看来您在searchConte方法的路由注释中缺少了一个等号:
名称“searchInv”
。它应该是name=“searchInv”
错误说明未启用批注,您确定它配置正确吗?看起来更像是您的控制器未正常工作?as控制器已使用@Route注释自动配置。请隔离问题,如果可能,请更新说明。因为我似乎在路线注释中遗漏了等号,我没有注意它。
public function findContes($cnt){
return $this->createQueryBuilder('contes')
->where('contes.titre LIKE :titre')
->setParameter('titre', '%'.$cnt.'%')
->getQuery()
->getResult();
}
/**
* @Route ("/invContes/search", name"searchInv")
* @param Request $request
* @param NormalizerInterface $Normalizer
* @return Response
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
*/
public function searchConte(Request $request, NormalizerInterface $Normalizer)
{
$repository = $this->getDoctrine()->getRepository(Inventairecontes::class);
$requestString=$request->get('searchValue');
$conte=$repository->findContes($requestString);
$jsonContent=$Normalizer->normalize($conte,'json',['groups'=>'contes']);
$retour = json_encode($jsonContent);
return new JsonResponse($jsonContent);
}