找不到映射文件

时间:2015-12-04 11:33:43

标签: php doctrine-orm mapping

我无法理解我错在哪里。这是抛出的异常

  

Doctrine \ Common \ Persistence \ Mapping \ MappingException抛出

     

找不到名为的映射文件   类的“Acme.Repository.Pass.Onpassrequest.dcm.xml”   '的Acme \库\通\ Onpassrequest'。

我的文件夹结构如下

- index.php
- bootstrap.php
/src
  /xml
    -Acme.Repository.Pass.Onpassrequest.dcm.xml
  /Acme
    /Repository
      /Pass
        - Onpassrequest.php
    /Web
      /WebInterface
        - OnPassRequestWebInterface.php

我的bootstrap.php是

<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\Request;
// Time zone;
date_default_timezone_set("Europe/Rome");

$loader = require "vendor/autoload.php";

// Create a simple "default" Doctrine ORM configuration for XML
$isDevMode = true;

$config = Setup::createXMLMetadataConfiguration(array("./src/xml"), $isDevMode);

// Database configuration parameters
$dbParams = array(
    'driver'    => 'pdo_mysql',
    'host'      => 'localhost',
    'user'      => 'uuu',
    'password'  => 'ppp',
    'dbname'    => 'ddd',
);

// Obtaining the entity manager
$em = EntityManager::create($dbParams, $config);

我想从./src/Acme/Web/WebInterface/OnPassRequestWebInterface.php文件调用getLayout($ user,$ roles,$ entirelist,$ root,\ Doctrine \ ORM \ EntityManager $ em)中的存储库。 $ roles有“管理员”值,所以它调用getUserLayout

<?php
namespace Acme\Web\WebInterface;

class OnPassRequestWebInterface{

    /**
     * 
     * @param array $user
     * @param array $roles
     * @param array $entirelist
     * @param string $root
     * @param \Doctrine\ORM\EntityManager $em
     */
    public static function getLayout($user, $roles, $entirelist, $root, \Doctrine\ORM\EntityManager $em){

        self::$user = $user;
        self::$roles = $roles;
        self::$entirelist = $entirelist;
        self::$root = $root;
        self::$em = $em;

        if(in_array("administrator", self::$roles)){

            self::getUserLayout();

        } else {

        }


    }


    public static function getUserLayout($period = "P2W"){

        $date = new \DateTime();

        $date->add(new \DateInterval($period));

        $qb = self::$em->createQueryBuilder();

        $qb->select("r")
            ->from("\\Acme\\Repository\\Pass\\Onpassrequest", "r")
            ->where("r.userId = :userId AND r.eventdate >= NOW() AND r.eventdate <= :enddate")
            ->orderBy("r.eventdate", "ASC")
            ->setParameters(array("userId"  =>  self::$user->ID,
                    "enddate"   =>  $date->format("Y-m-d")));

        $query = $qb->getQuery();

        $request = $query->getResult();

        $view = self::renderView("user-next-request.php", array($request), false);

        echo $view;

    }

有什么想法吗? 非常感谢你。

1 个答案:

答案 0 :(得分:0)

解决。

$config = Setup::createXMLMetadataConfiguration(array("./src/xml"), $isDevMode);

这是使用相对路径配置的。只需添加 DIR 即可

$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/src/xml"), $isDevMode);

错过了。 感谢