我已经按照本书的每一步进行操作,但我无法开始使用任何实体自定义存储库。
她的问题是我一直试图调用方法 filtrerExperienceTotal 但代码完成快捷方式(Ctrl-Space)无法找到方法,请帮忙
例如,我有我的用户实体:
<?php
namespace MTO\CrowdRiseBundle\Controller;
use MTO\CrowdRiseBundle\Entity\UserRepository;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use MTO\CrowdRiseBundle\Entity\User;
class ProfilsController extends Controller
{
public function filtrerExperienceTotal(){
$em = $this->getDoctrine()->getManager();
$req = $this->get('request');
if ($req->getMethod() == 'POST') {
$rechexperienceTot = $req->get('rechexperienceTotname');
$Users = $em->getRepository('MTOCrowdRiseBundle:User')->filtrerExperienceTotal(0,99);
if (!($Users == null)) {
return $this->render('MTOCrowdRiseBundle:Profils:profils.html.twig', array('users' => $Users));
} else {
return $this->render('MTOCrowdRiseBundle:Profils:profils.html.twig', array('users' => NUll));
}
}
return ($this->redirectToRoute('mto_crowd_rise_profils'));
}
和存储库类
class UserRepository extends EntityRepository
{
public function chercherNom($nom){
$qb = $this->getEntityManager()->createQueryBuilder('p')
->where('p.nom LIKE :nom')
->orWhere('p.prenom LIKE :nom')
->orWhere('p.username LIKE :nom')
->setParameter('nom', $nom)
->getQuery()->getResult();
return $qb;
}
public function filtrerExperienceTotal($experiencemin,$experiencemax){
$qb = $this->getEntityManager()->createQueryBuilder('p')
->select('p ')
->where('p.experienceTot between :parm1 and :param2')
->setParameter('param1', $experiencemin)
->setParameter('param2', $experiencemax)
->getQuery()->getResult();
return $qb;
}
}
最终使用user.orm.yml
MTO \ CrowdRiseBundle \实体\用户: 类型:实体 表:用户 repositoryClass:MTO \ CrowdRiseBundle \ Entity \ UserRepository
id:
id:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: IDENTITY
fields:
nom:
type: string
nullable: false
length: 40
fixed: false
comment: ''
prenom:
type: string
nullable: false
length: 40
fixed: false
comment: ''
datenaissance:
type: date
nullable: false
comment: ''
column: dateNaissance
situationprof:
type: string
nullable: false
length: null
fixed: false
comment: ''
column: situationProf
secteur:
type: string
nullable: false
length: null
fixed: false
comment: ''
experiencetot:
type: integer
nullable: false
unsigned: false
comment: ''
column: experienceTot
solde:
type: integer
nullable: false
unsigned: false
comment: ''
column: solde
paysnatal:
type: string
nullable: false
length: 40
fixed: false
comment: ''
column: paysNatal
image:
type: text
nullable: false
length: null
fixed: false
comment: ''
role:
type: string
nullable: false
length: null
fixed: false
comment: ''
etat:
type: string
nullable: false
length: null
fixed: false
comment: ''
sexe:
type: string
nullable: false
length: null
fixed: false
comment: ''
lifecycleCallbacks: { }
拜托,我真的需要帮助
答案 0 :(得分:0)
最后,问题来自IDE,所有我需要的是强制它并手动编写方法的名称,它工作正常,非常感谢