Search code examples
doctrine-ormzend-framework2mezzio

Use its functions in the repository (Doctrine + Zend Expressive)


Welcome. It is impossible to call its functions from the repository in an Action (Expressive Zend + Doctrine)

___________________

// App\Entity\Category
namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Category
 *
 * @ORM\Table(name="category", indexes={@ORM\Index(name="id", columns={"id"})})
 * @ORM\Entity(repositoryClass="App\Repository\CategoryRepository")
 */
class Category
{//}
___________________

// App\Repository\CategoryRepository
namespace App\Repository;

use Doctrine\ORM\EntityRepository;

class CategoryRepository extends EntityRepository
{
    public function finderMethod($arguments){
        // Какие-либо действия
        return $arguments;
    }
}
___________________

// App\Action\PageAction
$category = $this->em->getRepository('App\Entity\Category')-> ???

findAll(), findBy working as intended, what am I doing wrong? (as far as I remember, in zf2 I had the same problem)


Solution

  • To get a repository you can use the fully qualified class name:

    <?php 
    
    $categoryRepository = $this->em->getRepository(App\Entity\Category::class);