我已经检查了这个,但我的错误似乎有所不同.
我收到此错误:
[2012-05-07 14:09:59] request.CRITICAL: BadMethodCallException: Undefined method 'findOperariosordenados'. The method name must start with either findBy or findOneBy! (uncaught exception) at /Users/gitek/www/uda/vendor/doctrine/lib/Doctrine/ORM/EntityRepository.php line 201 [] []
Run Code Online (Sandbox Code Playgroud)
这是我的OperarioRepository:
<?php
namespace Gitek\UdaBundle\Entity;
use Doctrine\ORM\EntityRepository;
/**
* OperarioRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class OperarioRepository extends EntityRepository
{
public function findOperariosordenados()
{
$em = $this->getEntityManager();
$consulta = $em->createQuery('SELECT o FROM GitekUdaBundle:Operario o
ORDER BY o.apellidos, o.nombre');
return $consulta->getResult();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器,我在其中调用存储库:
$em = $this->getDoctrine()->getEntityManager();
$operarios = $em->getRepository('GitekUdaBundle:Operario')->findOperariosordenados();
Run Code Online (Sandbox Code Playgroud)
最后,这是我的实体:
<?php
namespace Gitek\UdaBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Gitek\UdaBundle\Entity\Operario
*
* @ORM\Table(name="Operario")
* @ORM\Entity(repositoryClass="Gitek\UdaBundle\Entity\OperarioRepository")
*/
class Operario
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string $nombre
*
* @ORM\Column(name="nombre", type="string", length=255)
*/
private $nombre;
----
----
Run Code Online (Sandbox Code Playgroud)
任何帮助或线索?
提前致谢
编辑:在开发环境中工作正常,但在prod环境中没有.
你已经处于一个reposoritory,你不需要重新获得它.
*存储库中的所有方法都可以用作 $this
另外,请注意
return $this->findBy();
可以使用简单时,查询生成器或手工查询是太多的工作.findBy()
有三个参数,第一个是关系和getter数组,第二个是排序,参见Doctrine\ORM\EntityRepository
代码你的代码
我建议你干脆做:
public function findOperariosordenados()
{
$collection = $this->findBy( array(), array('apellidos','nombre') );
return $collection;
}
Run Code Online (Sandbox Code Playgroud)
你只需要 EntityRepository
我的一个存储库:
注意事项:
Order
与$owner
使用User
实体有关系$array = $reposiroty->getOneUnhandledContainerCreate(Query::HYDRATE_ARRAY)
ContainerCreateOrder
是一个延长的Order
在@ORM\InheritanceType("SINGLE_TABLE")
.但是,这个问题的范围很大.它可能会有所帮助:
<?php
namespace Client\PortalBundle\Entity\Repository;
# Internal
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Query;
use Doctrine\Common\Collections\ArrayCollection;
# Specific
# Domain objects
# Entities
use Client\PortalBundle\Entity\User;
# Exceptions
/**
* Order Repository
*
*
* Where to create queries to get details
* when starting by this Entity to get info from.
*
* Possible relationship bridges:
* - User $owner Who required the task
*/
class OrderRepository extends EntityRepository
{
private function _findUnhandledOrderQuery($limit = null)
{
$q = $this->createQueryBuilder("o")
->select('o,u')
->leftJoin('o.owner', 'u')
->orderBy('o.created', 'DESC')
->where('o.status = :status')
->setParameter('status',
OrderStatusFlagValues::CREATED
)
;
if (is_numeric($limit))
{
$q->setMaxResults($limit);
}
#die(var_dump( $q->getDQL() ) );
#die(var_dump( $this->_entityName ) );
return $q;
}
/**
* Get all orders and attached status specific to an User
*
* Returns the full Order object with the
* attached relationship with the User entity
* who created it.
*/
public function findAllByOwner(User $owner)
{
return $this->findBy( array('owner'=>$owner->getId()), array('created'=>'DESC') );
}
/**
* Get all orders and attached status specific to an User
*
* Returns the full Order object with the
* attached relationship with the User entity
* who created it.
*/
public function findAll()
{
return $this->findBy( array(), array('created'=>'DESC') );
}
/**
* Get next unhandled order
*
* @return array|null $order
*/
public function getOneUnhandledContainerCreate($hydrate = null)
{
return $this->_findUnhandledOrderQuery(1)
->orderBy('o.created', 'ASC')
->getQuery()
->getOneOrNullResult($hydrate);
}
/**
* Get All Unhandled Container Create
*/
public function getAllUnhandledContainerCreate($hydrate = null)
{
return $this->_findUnhandledOrderQuery()
->orderBy('o.created', 'ASC')
->getQuery()
->getResult($hydrate);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15558 次 |
最近记录: |