致命错误:调用未定义的方法MyModuleEntityMyEntity::findAll()原理orm 2 zf


Fatal error: Call to undefined method MyModuleEntityMyEntity::findAll() doctrine orm 2 zf2

我从几个月开始就开始学习教义,但无法解决这个问题。

好吧的细节

composer.json

"name" : "zendframework/skeleton-application",
  "description" : "Skeleton Application for ZF2",
  "require" : {
    "php" : ">=5.3.3",
    "zendframework/zendframework" : "~2.4",
    "doctrine/doctrine-orm-module" : "0.9.2",
    "doctrine/doctrine-module" : "0.9.0",
    "zendframework/zend-developer-tools" : "0.0.2",
    "bjyoungblood/BjyProfiler" : "v1.1.0"
  },
  "license" : "BSD-3-Clause",
  "keywords" : [ "framework", "zf2" ],
  "homepage" : "http://framework.zend.com/"
}

application.config.php

<?php
return array(
    'modules' => array(
        'ZendDeveloperTools',
        'DoctrineModule',
        'DoctrineORMModule',
        'BjyProfiler',
        'Application',
        'Publicacion',
    ),
        'module_paths' => array(
            './module',
            './vendor','./module','./module',
        ),
        'config_glob_paths' => array(
            'config/autoload/{,*.}{global,local}.php',
         ),
    ),
);

module.config.php

namespace Publicacion;
return array(
    'controllers' => array(
        'invokables' => array(
            'Publicacion'Controller'Publicacion' => 'Publicacion'Controller'PublicacionController',
            'Publicacion'Controller'Categoria' => 'Publicacion'Controller'CategoriaController',
        ),
    ),
    'router' => array(
        'routes' => array(
            'publicacion' => array(
                'type'    => 'Literal',
                'options' => array(
                    // Change this to something specific to your module
                    'route'    => '/publicacion',
                    'defaults' => array(
                        // Change this value to reflect the namespace in which
                        // the controllers for your module are found
                        '__NAMESPACE__' => 'Publicacion'Controller',
                        'controller'    => 'Publicacion',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    // This route is a sane default when developing a module;
                    // as you solidify the routes for your module, however,
                    // you may want to remove it and replace it with more
                    // specific routes.
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),),),
                    'categoria' => array(
                        'type'    => 'segment',
                        'options' => array(
                            // Change this to something specific to your module
                            'route'    => '/categoria',
                            'defaults' => array(
                                // Change this value to reflect the namespace in which
                                // the controllers for your module are found
                                '__NAMESPACE__' => 'Publicacion'Controller',
                                'controller'    => 'Categoria',
                                'action'        => 'index',
                            ),),),),),),),
    'view_manager' => array(
        'template_path_stack' => array(
            'Publicacion' => __DIR__ . '/../view',
        ),
        'display_exceptions' => true,
    ),
    'doctrine' => array(
        'driver' => array(
            __NAMESPACE__ . '_driver' => array(
                'class' => 'Doctrine'ORM'Mapping'Driver'AnnotationDriver',
                'cache' => 'array',
                'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
            ),
            'orm_default' => array(
                'drivers' => array(
                    __NAMESPACE__ . ''Entity' => __NAMESPACE__ . '_driver'
                )))));

控制器

namespace Publicacion'Controller;
use Zend'Mvc'Controller'AbstractActionController;
use Publicacion'Entity'Publicacion;
use Doctrine'ORM'EntityManager;
class PublicacionController extends AbstractActionController
{
    public function getEntityManager()
    {
        return $this->getServiceLocator()->get('Doctrine'ORM'EntityManager');
    }
    public function indexAction()
    {
        //var_dump($this->getEntityManager());
        $publicaciones = $this->getEntityManager()->getRepository('Publicacion'Entity
'Publicacion')->findAll(); // <-- HERE 
        return array('publicaciones' => $publicaciones);
    }
}

index.phtml

<table>
<?php
foreach ($publicaciones as $publicacion){
    echo "<tr>";
    echo "<td>".$publicacion->getId()."</td>";
    echo "<td>".$publicacion->getTitulo()."</td>";
    echo "</tr>";
}
?>
</table>

文本错误为:

致命错误:调用未定义的方法中的Publicacion''Entity''Publicacion::findAll()C: ''examplep''htdocs''MyProyect''module''Publicacion''src''Publicacion''Controller''PublicacionController.php在线29

出版实体

namespace Publicacion'Entity;
use Publicacion'Entity'Categoria;
use Publicacion'Entity'Referencia;
use Doctrine'ORM'Mapping as ORM;
use Zend'Form'Annotation;
use Doctrine'Common'Collections'Collection;
use Zend'Db'Sql'Ddl'Column'Boolean;
/**
 * 
 * @author Darwin
 *
 * Publicacion
 *
 * @ORM'Table(name="publicacion")
 * @ORM'Entity(repositoryClass="Publicacion'Entity'Publicacion")
 * @Annotation'Name("Publicacion")
 * @Annotation'Hydrator("Zend'Stdlib'Hydrator'ClassMethods")
 */
class Publicacion
{
     /**
     * @ORM'Id
     * @ORM'GeneratedValue(strategy="AUTO")
     * @ORM'Column(type="integer")
     * @Annotation'Exclude()
     * @var int|null
     */
    private $id;
    /**
     * @ORM'Column(type="string")
     * 
     * @var string
     */
    private $titulo;
    /**
     * @ORM'Column(type="string")
     * @var string
     */
    private $introduccion;
    /**
     * @ORM'Column(type="string")
     * @var string
     */
    private $contenido;

    // relación muchos a muchos una referencia puede referenciar a muchas publicaciones y viserversa
    /**
     * @ORM'ManyToMany(targetEntity="Referencia", inversedBy="publicaciones")
     * @ORM'JoinTable(name="publicacion_referencia")
     * @var Collection
     */
    private $referencias;
    // relación muchos a muchos, una categoria puede referenciar a muchas publicaciones y viserversa
    /**
     * @ORM'ManyToMany(targetEntity="Categoria", inversedBy="publicaciones")
     * @ORM'JoinTable(name="publicacion_categoria")
     * @var Collection
     */
    private $categorias;
    //****** MODULO COMENTARIO **********
    // relación uno a muchos ( una publicación puede referenciar muchos comentarios / un comentario solo puede referenciar una publicación o otro comentario)
    /**
     *-ORM'OneToMany(targetEntity="Comentario", mappedBy="publicacion")
     *-var Collection
     */
    //private $comentarios;
    /**
     * @ORM'Column(type="datetime")
     * @var 'DateTime
     */
    private $fechaCreado;
    /**
     * @ORM'Column(type="datetime")
     * @var 'DateTime
     */
    private $fechaModificado;
    /**
     * @ORM'Column(type="boolean")
     * @var Boolean
     */
    private $publicado;
// property methods ....
}
?>

有人能帮忙吗?

Bram Gerritsen,根据您的评论,我可以看到错误,问题是注释

* @ORM'Entity(repositoryClass="Publicacion'Entity'Publicacion") 

,我没有使用自定义存储库,并且指示了与repos相同的实体。。。现在工作正常,将注释更改为

* @ORM'Entity 

非常感谢你的帮助!