2015-11-04 49 views
2

我从几个月起就开始学习,并且无法解决此问题。致命错误:调用未定义的方法MyModule Entity MyEntity :: findAll()doctrine orm 2 zf2

以及细节

composser.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> 

文字错误是:

Fatal error: Call to undefined method Publicacion\Entity\Publicacion::findAll() in C:\xampp\htdocs\MyProyect\module\Publicacion\src\Publicacion\Controller\PublicacionController.php on line 29

的Publicacion实体

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 .... 
} 

?> 

任何人都可以帮忙吗?

+1

请包括您的实体。特别是EntityRepository注释。 –

+0

包括Publicacion实体,我想我正在理解问题... –

+0

问题是注释* @ORM \ Entity(repositoryClass =“Publicacion \ Entity \ Publicacion”),我没有使用自定义存储库,并指出与回购相同的实体...现在正常工作,更改注释以便* @ORM \ Entity。非常感谢您的帮助! –

回答

0

布拉姆Gerritsen的,与您的意见,我可以看到错误,问题是注释

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

,我没有使用自定义的存储库,并表示相同的实体回购...现在工作正常,更改注释以便

* @ORM\Entity 

非常感谢您的帮助!

+0

很高兴我能帮你解决问题。 –

相关问题