douya7309 2019-07-27 01:56
浏览 91

PHP Doctrine无法找到映射实体?

I am trying to setup XML mapping in doctrine. Whenever I go to create the database using the CLI orm:schema-tools:create it tells me:

[OK] No Metadata Classes to process.

Here is my code and folder structure:

    /public_html
        /Model
            User.php
        /xml
            Model.User.dcm.XML

        bootstrap.php
        register.php

    /vendor
    cli_config.php
    composer.json

bootstrap.php code:

    <?php
    use Doctrine\ORM\EntityManager,
        Doctrine\ORM\Configuration;

    require_once __DIR__ . '/../vendor/autoload.php';

    $isDevMode = true;

    //set doctrine configurations

    if ($isDevMode) {
        $cache = new \Doctrine\Common\Cache\ArrayCache;
    } else {
        $cache = new \Doctrine\Common\Cache\ApcCache;
    }

    $config = new Configuration;
    $config->setMetadataCacheImpl($cache);
    $driverImpl = new \Doctrine\ORM\Mapping\Driver\XmlDriver(array(__DIR__ . '/xml/'));
    $config->setMetadataDriverImpl($driverImpl);
    $config->setQueryCacheImpl($cache);
    $config->setProxyDir(__DIR__ . '/Proxy');
    $config->setProxyNamespace('Proxy');

    if ($isDevMode) {
        $config->setAutoGenerateProxyClasses(true);
    } else {
        $config->setAutoGenerateProxyClasses(false);
    }


    // the connection configuration
    $dbParams = array(
        'dbname' => 'mafiaage_dev',
        'user' => 'root',
        'password' => 'pass',
        'host' => '3x.x.x',
        'driver' => 'pdo_mysql',
    );

    $em = EntityManager::create($dbParams, $config); 

Model/User.php code:


    <?php
    namespace Model;

    Class User {

        protected $id;
        protected $name;
        protected $password;

        public function setName($name)
        {
            $this->name = $name;
        }
        public function setPassword($password)
        {
            $this->name = $password;
        }

    }

    ?>

xml/Model.User.dcm.XML code:


    <doctrine-mapping>

        <entity name="Model\User">

            <id name="id" type="integer" column="user_id">
                <generator strategy="AUTO" />
            </id>
            <field name="name" type="string" />
            <field name="password" type="string" />

        </entity>

    </doctrine-mapping>

First time using stackoverflow so I hope I formatted this properly. Thanks!

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥50 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?