The method name must begin with findBy or findOneBy! (uncaught exception)

I already checked, but my error seems to be different.

I get this error:

[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 [] []

This is my 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();
    }    
}

This is my controller where I call the repository:

$em = $this->getDoctrine()->getEntityManager();
$operarios = $em->getRepository('GitekUdaBundle:Operario')->findOperariosordenados();   

Finally, this is my object:

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

Any help or hint?

Thanks in advance

EDIT: Works fine in the Dev environment, but not in the prod environment.

+3
source share
3 answers

You are already in the repository, you do not need to receive it again.

All methods in * Repositories can be used as with $this

Also pay attention

  • Query Builder or Hand made Query is too much work when you can use simple return $this->findBy();.
  • findBy() : - , - , . Doctrine\ORM\EntityRepository code
  • ... FIRST. .

:

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

EntityRepository

:

:

  • Order $owner, User Entity
  • , $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);
    }
}
+7

?

php app/console cache:clear --env=prod --no-debug

+5

My app/config/config_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 .

- .

. () -, (php - Apache APC? - )

apc.stat = 1 (http://php.net/manual/en/apc.configuration.php#ini.apc.stat) /etc/php5/apache2php.ini , : apache + APC ?

UPDATE

APC, APCu. apcu_clear_cache() PHP Fatal, , , APC.

, , , apcu_clear_cache() apc_clear_cache(). -, .

if APC APCu.

0
source

All Articles