无法调用自定义存储库方法 symfony2
Can't call a custom respository methode symfony2
我已经按照书中的每一步操作,但我无法开始使用任何实体自定义存储库。
她的问题是我一直在尝试调用方法 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
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\Entity\User:
类型:实体
table: 用户
存储库类:MTO\CrowdRiseBundle\Entity\User存储库
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: { }
伙计们,我真的需要帮助
最后,问题出在 IDE,我需要的只是强制它并手动写入方法的名称,它工作正常,非常感谢
我已经按照书中的每一步操作,但我无法开始使用任何实体自定义存储库。
她的问题是我一直在尝试调用方法 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
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\Entity\User: 类型:实体 table: 用户 存储库类:MTO\CrowdRiseBundle\Entity\User存储库
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: { }
伙计们,我真的需要帮助
最后,问题出在 IDE,我需要的只是强制它并手动写入方法的名称,它工作正常,非常感谢