【问题标题】:Can't call a custom respository methode symfony2无法调用自定义存储库方法 symfony2
【发布时间】:2016-02-20 12:45:27
【问题描述】:

我已按照本书中的每一步操作,但无法使用任何实体自定义存储库。
她的问题是我一直在尝试调用方法 filterExperienceTotal 但是代码完成快捷方式(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; 

 }
}

最终用户.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: {  }

拜托各位,我真的需要帮助

【问题讨论】:

  • 所以问题出在您的 IDE 自动完成功能上?不在应用程序/代码中?
  • 这似乎不是 symfony 的问题。您使用的是哪个 IDE?
  • 我正在使用 netbeans,Symfony_Standard_Vendors_2.6.4.zip。我真的不知道该怎么办:(
  • 来自$em-&gt;getE的getE是什么?
  • 这是我后来删除的东西,但问题仍然存在

标签: symfony symfony-2.1 symfony-2.3


【解决方案1】:

最后,问题来自 IDE,我只需要强制它并手动编写方法的名称,它工作正常,非常感谢

【讨论】:

    猜你喜欢
    • 2012-11-14
    • 1970-01-01
    • 2018-01-05
    • 2013-02-17
    • 2018-02-09
    • 2019-09-30
    • 2017-11-03
    • 2017-06-18
    • 1970-01-01
    相关资源
    最近更新 更多