Symfony 方法名称必须以findBy或findOneBy开头!(未捕获的例外)

Symfony 方法名称必须以findBy或findOneBy开头!(未捕获的例外),symfony,Symfony,我已经检查过了,但我的错误似乎不同 我得到这个错误: [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/doct

我已经检查过了,但我的错误似乎不同

我得到这个错误:

[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 [] []
这是我的操作库:

<?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();
    }    
}
$em = $this->getDoctrine()->getEntityManager();
$operarios = $em->getRepository('GitekUdaBundle:Operario')->findOperariosordenados();   
最后,这是我的实体:

<?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;
    ----
    ----

你清除缓存了吗


php应用程序/控制台缓存:clear--env=prod--no debug

您已经在一个repository中,不需要重新获取它

*存储库中的所有方法都可以与
$this

另外,请注意

  • 当一个简单的
    返回$this->findBy()时,查询生成器或手工查询的工作量太大了可以使用
  • findBy()
  • 而不是使用原始查询。。。首先尝试查询生成器。看看我的样品
您的代码

我建议您只需执行以下操作:

public function findOperariosordenados()
{
    $collection = $this->findBy( array(), array('apellidos','nombre') );
    return $collection;
} 
您只需要
EntityRepository

我的一个存储库:

注意事项:

  • 订单
    与使用
    用户
    实体的
    $owner
    有关系
  • 如果确实需要数组,请在
    $array=$reposiroty->getOneUnhandledContainerCreate(Query::hydrome\u array)
  • ContainerCreateOrder
    @ORM\InheritanceType(“单表”)
    中的
    Order
    的扩展。但这完全超出了这个问题的范围
这可能会有帮助:

 <?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);
    }
}

My
app/config/config\u prod.yml
已为以下命令指定了缓存驱动程序:

doctrine:
    orm:
        metadata_cache_driver: apc
        result_cache_driver: apc
        query_cache_driver: apc
我使用以下函数调用清除了APC缓存:

if (function_exists('apcu_clear_cache')) {
    // clear system cache
    apcu_clear_cache();
    // clear user cache
    apcu_clear_cache('user');
}

if (function_exists('apc_clear_cache')) {
    // clear system cache
    apc_clear_cache();
    // clear user cache
    apc_clear_cache('user');
    // clear opcode cache (on old apc versions)
    apc_clear_cache('opcode');
}
并清空
app/cache/
目录

但是我在prod环境中不断遇到这个错误,而在dev环境中一切正常

我终于重新启动了我的虚拟服务器,成功了

这肯定让我怀疑缓存有问题。下次我将尝试(优雅地)仅重新启动web服务器,因为这也会清除缓存()

否则,在
/etc/php5/apache2hp.ini
中设置
apc.stat=1
()似乎也是一个好主意,如下所示:

更新

我的开发服务器安装了APC,而不是APCu。对
apcu\u clear\u cache()
的前两个调用导致了一个PHP致命错误,从而阻止了APC缓存被清除

因此,在调用
apcu\u clear\u cache()
apc\u clear\u cache()
之前,请检查系统使用的缓存。之后,无需重新启动虚拟机或web服务器来清除缓存并消除严重异常

添加
if
块以运行APC或APCu特定功能