【问题标题】:how to generate a table from entity using doctrine orm in own MVC application?如何在自己的 MVC 应用程序中使用教义 orm 从实体生成表?
【发布时间】:2017-01-11 01:08:06
【问题描述】:

无法在其自己的 MVC 应用程序中使用教义 ORM 从实体 (PatMon2.php) 生成表。

应用结构是:

/public
/src
..../core   with COntroller, View, Router, Request  and App.php
..../monBundle/Entity/PatMon2.php
....bootstrap.php
/vendor
compose.json

and some other folders and files.

我无法从PatMon2.php 实体生成表,并且我从不同的项目(www\Plan2ow 而不是 www\patmon2)获取消息。当我创建一个项目时,我已经复制了它并更改了命名空间。我还删除了 vendor 文件夹和 composer.lock 并使用其他捆绑软件重新安装了学说。我使用搜索工具检查了新项目中不存在旧命名空间,在新项目中找不到单词“Plan2own”。尽管如此,我无法为新项目生成表,并且收到包含旧项目命名空间“Plan2own”的错误消息。

如果我使用网址:http://patmon2/index.php/home 我可以看到我可以包含 /src/bootsrap.php 文件和 /vendor/composer/autoload_real.php。 但是如果我在命令行上运行教义:orm,它会抱怨它不能包含供应商目录。

index.php

<?php
print_r("C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\patmon2\public\index.php");
require '../src/bootstrap.php'; //which requires autoload.php

bootstrap.php

<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
echo( "<br> in bootstrap INC_ROOT = ".INC_ROOT );
require_once '../vendor/autoload.php';
<...>

供应商/autoload.php

<?php 
<...>
        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');
        if ($useStaticLoader) {
            require_once __DIR__ . '/autoload_static.php';
            print_r("<br>uses static loader");
            call_user_func(\Composer\Autoload\ComposerStaticInit87d6e473c75d808eefba33ccc9231657::getInitializer($loader));
        }

http://patmon2/index.php/home中输出

C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\patmon2\public\index.php
in bootstrap INC_ROOT = C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\patmon2
uses static loader

命令行错误: c:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\patmon2&gt;vendor\bin\doctrine orm:schema-tool:update --force --dump-sql

或 c:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\patmon2>php vendor\doctrine\orm\bin\doctrine

    uses static loader <br> in bootstrap<br> in bootstrap INC_ROOT = C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\patmon2PHP 
Warning:  require_once(../vendor/autoload.php): failed to open stream: No such file or directory 
in C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\patmon2\src\bootstrap.php on line 69
    PHP Fatal error:  require_once(): Failed opening required '../vendor/autoload.php' 
(include_path='C:\Bitnami\wampstack-5.6.20-0\php\PEAR;C:\Bitnami\wampstack-5.6.20-0\frameworks\smarty\libs;C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\Plan2own\vendor;C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\patmon2\vendor') 
in C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\patmon2\src\bootstrap.php on line 69

如果我使用&gt;php vendor\bin\doctrine,我会得到文件内容输出:

dir=$(d=${0%[/\\]*}; cd "$d"; cd "../doctrine/orm/bin" && pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
        # Cygwin paths start with /cygdrive/ which will break windows PHP,
        # so we need to translate the dir path to windows format. However
        # we could be using cygwin PHP which does not require this, so we
        # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
        if [[ $(which php) == /cygdrive/* ]]; then
                dir=$(cygpath -m "$dir");
        fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/doctrine" "$@"

但是如果我使用 c:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\patmon2>php vendor\doctrine\orm\bin\doctrine 我得到了上面的错误,它抱怨不能包括“../vendor/autoload.php”。如果我更改此路径,则网站无法正常工作。 ** ############################################### ############## ** 这是问题的旧版本。我在 indexp.php、bootstrap.php 文件中做了一些我不记得的更改。还包括 ...patmon2/vendor 目录到 php.ini 文件

命令: c:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\patmon2> vendor\bin\doctrine orm:schema-tool:update --force --dump-sql

Gives this output:
 <br> index.php  vendorDir  = **string(64) "C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\Plan2own\vendor"
**<br> index.php  baseDir  = **string(57) "C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\Plan2own"
**<br> index.php  vendorDir  = **string(64) "C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\Plan2own\vendor"
**<br> index.php  baseDir  = **string(57) "C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\Plan2own"
**No Metadata Classes to process.

我已经对所有文件夹进行了“Plan2own”搜索,但没有找到该字符串。我使用命令行在“www\patmon2”上。 为什么我从不同的命名空间获取日志?以及如何告诉学说 ORM,我想将其转换为表格的实体文件在哪里?

我的 composer.json

   "autoload": {
        "psr-4": {
            "core\\" : "/src/core/",
            "src\\monBundle\\Entity\\" : "/src/monBundle/Entity/",
            "src\\monBundle\\Controller\\" : "/src/monBundle/Controller/",
            "src\\monBundle\\JsonData\\" : "/src/monBundle/JsonData/",
            "src\\monBundle\\cache\\" : "/src/monBundle/cache/",
            "src\\monBundle\\resources\\" : "/src/monBundle/resources/"
        },
        "classmap": [
            "src/core/App.php",
            "src/core/View.php",
            "src/core/Controller.php"
        ]
    },    

    "require": {
        "doctrine/orm": "^2.5",
        "symfony/console": "~2.5",
        "twig/twig": "^1.24",
        "filp/whoops": "^2.1"
    }  

【问题讨论】:

    标签: orm doctrine-orm composer-php


    【解决方案1】:

    最后,原因是包含路径错误。当我完成项目时,我会将其上传到 github。

    简而言之 C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\patmon2\src\bootstrap.php 必须包含require_once __DIR__.'/../vendor/autoload.php'; 行(不是require_once '../vendor/autoload.php';

    在 Windows 上我应该使用命令:php vendor\doctrine\orm\bin\doctrine(不是vendor\bin\doctrine,或php vendor\bin\doctrine)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-07
      • 1970-01-01
      • 2015-04-04
      • 1970-01-01
      • 2014-02-01
      • 1970-01-01
      • 2021-11-21
      • 2013-11-09
      相关资源
      最近更新 更多