를 사용하여 데이터베이스/단체에서 임의의 레코드를 가져 교리와 임의의 레코드를 반환 다음CI2 + Doctrine2
$name = Doctrine::getTable('nametable')
->createQuery()
->select('name')
->orderBy('RAND()')
->fetchOne();
하지만 CI2 + Doctrine2를 실행 해요, 그래서 그것을 Call to undefined method Doctrine::getTable()
나는
$data = $this->doctrine->em->getRepository('ORM\Project\Names')
->orderBy('RAND()')
->fetchOne();
을 시도했다하지만이 중 하나가 작동하지 않습니다
Uncaught exception 'BadMethodCallException' with message 'Undefined method 'orderBy'. The method name must start with either findBy or findOneBy!'
아마도 findOneBy를 원하지만 배열이 필요합니다.
이 설정에서 임의의 레코드를 가져 오는 우아한 방법이 있습니까?
편집 :
내가 가지고 올 한 일이 있습니다 :
$query = $this->doctrine->em->createQuery("select max(u.id) from ORM\Dynasties2\Femalenames u");
$result = $query->getSingleResult();
$highval = $result[1];
$random_name = rand(1,$highval);
$name = $this->doctrine->em->find('ORM\Dynasties2\Femalenames', $random_name);
$mother_name = $name->getName();
가 확실히 청소기 방법이 ??? 분명히 CI2/Doctrine2에는 RAND()와 같은 것이 없으며 SQL 쿼리를 작성하기에는 부족합니다.
네, 그게 그걸 다룰 수있는 교리입니다. 다음과 같은 함수를 사용할 수도 있습니다 : https://gist.github.com/Thinkscape/124d658e4076421c0516 –