在存储库中使用它的功能(Doctrine + Zend Expressive)

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

欢迎光临。无法在 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 按预期工作,我做错了什么? (据我所知,在 zf2 中我遇到了同样的问题

你遇到了什么错误?你确定 $this->em 是 Entity Manager 的一个实例吗?虽然这不是必需的;尝试像这样在 App 前添加反斜杠:

<?php 
     $this->em->getRepository('\App\Entity\Category')->??? 

要获取存储库,您可以使用完全限定的 class 名称:

<?php 

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