PHP Doctrine 初学者:找不到 DoctrineORMToolsSetup [英] PHP Doctrine Beginner: DoctrineORMToolsSetup not found

查看:23
本文介绍了PHP Doctrine 初学者:找不到 DoctrineORMToolsSetup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是学说的初学者.我刚刚安装了 pear + 学说 2.3.3,想测试一下.

为了测试教义,我写了一个名为person"的类

/*** @实体*/班级人{/** @Id @Column(type="integer") @GeneratedValue * */私人 $id;/** @Column(type="string") * */私人 $name;/** @Column(type="string") * */私人$姓氏;//一些getter和setter ...}

之后我创建了 bootstrap.php 文件、bootstrep_doctrine.php 和 cli-config.php 文件并运行命令:

学说 orm:schema-tool:create

效果很好!

但是现在,当我想将 bootstrap.php 包含在普通"php 文件中以创建人"时,我收到以下错误:

致命错误:找不到类 'DoctrineORMToolsSetup'在/var/www/vms/bootstrap_doctrine.php 第 15 行

文件如下所示:

setName("Hans");?>

bootstrap.php:

if(!class_exists("DoctrineCommonVersion", false)){需要一次'bootstrap_doctrine.php';}

bootstrap_doctrine.php

使用 DoctrineORMToolsSetup;使用 DoctrineORMEntityManager;$paths = array("实体/");$isDevMode = 真;//连接配置$dbParams = 数组('司机' =>'pdo_mysql','用户' =>'测试','密码' =>'测试','数据库名' =>'测试',);$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);$em = EntityManager::create($dbParams, $config);

我检查了/usr/share/pear/是否在 php_include 路径中.它是..

require_once 'System.php';var_dump(class_exists('System', false));

它返回真:

但是这个确实返回 false:

使用 DoctrineORMToolsSetup;var_dump(class_exists('Setup', false));

我做错了吗?

最好的问候

解决方案

是的,似乎缺少自动加载,自动加载类的最简单方法是使用 Composer,它还可以下载 Doctrine 等依赖项.为此,您必须将 composer.phar 安装在本地项目根目录或全局安装在 PATH 系统变量中声明的文件夹(/usr/local/bin/ 是推荐的文件夹).p>

然后您必须在项目的根文件夹中编辑 composer.json 文件.在此文件中,您将定义项目的依赖项以及您希望能够加载的类路径.

<代码>{要求": {学说/ORM":2.3.3"},自动加载":{psr-0":{MyProject\Models\":src/models/"}}}

然后您所要做的就是从项目的根文件夹中打开一个终端并输入 composer install.这将创建一个包含所有下载依赖项的供应商文件夹.您还将在此供应商文件夹中获得 autoload.php 文件.你只需要在你的 php 文件中包含这个自动加载器,就可以使用你在 composer.json 的自动加载部分声明的所有依赖项和所有命名空间.

您可以在此处获取有关作曲家的更多信息:https://getcomposer.org/您还可以在此处浏览可用的软件包:https://packagist.org/

希望这会有所帮助

im a beginner with doctrine. I just installed pear + doctrine 2.3.3 and want to test it.

to test doctrine i wrote a class named "person"

/**
 * @Entity
 */
class person
{
    /** @Id @Column(type="integer") @GeneratedValue * */
    private $id;

    /** @Column(type="string") * */
    private $name;

    /** @Column(type="string") * */
    private $surname;

    //some getters and setters ...
}

after that i made my bootstrap.php file, bootstrep_doctrine.php and cli-config.php files and run the command:

doctrine orm:schema-tool:create

that works fine!

But now, when i want to include my bootstrap.php in a "normal" php file, to create a "person" i get the following error:

Fatal error: Class 'DoctrineORMToolsSetup' not found 
in /var/www/vms/bootstrap_doctrine.php on line 15

The file looks like follows:

<?php
$debug = true;
if($debug){
    error_reporting(E_ALL);
    ini_set("display_errors", "on");
    ini_set("display_startip_errors", "on");
}
require_once '../bootstrap.php';

include_once ('testClassOrm.php');
$person = new person();
$person = new person();
$person->setName("Hans");
?>

bootstrap.php:

if(!class_exists("DoctrineCommonVersion", false)){
    require_once 'bootstrap_doctrine.php';
}

bootstrap_doctrine.php

use DoctrineORMToolsSetup;
use DoctrineORMEntityManager;

$paths = array("entities/");
$isDevMode = true;

// the connection configuration
$dbParams = array(
    'driver'   => 'pdo_mysql',
    'user'     => 'TEST',
    'password' => 'TEST',
    'dbname'   => 'test',
);

$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$em = EntityManager::create($dbParams, $config);

i checked if the /usr/share/pear/ is in php_include path. and it is ..

require_once 'System.php';
var_dump(class_exists('System', false));

it returns true:

but this one does return false:

use DoctrineORMToolsSetup;
var_dump(class_exists('Setup', false));

Am i doing something wrong?

best regards

解决方案

Yes it seems that autoloading is missing, the easiest way to autoload your classes is to use Composer which can also download dependencies such as Doctrine. To do this you have to get composer.phar installed either locally on your project root or globally on folder declared in your PATH system variable (/usr/local/bin/ is the recommended folder).

Then you have to edit a composer.json file in your project's root folder. In this file you will define your project's dependencies and the class pathes you want to be able to load.

{
    "require": {
        "Doctrine/ORM": "2.3.3"
    },
    "autoload": {
        "psr-0": {"MyProject\Models\": "src/models/"}
    }
}

Then all you have to do is to open a terminal from your project's root folder and type composer install. This will create a vendor folder containing all the downloaded dependencies. You will also get an autoload.php file in this vendor folder. You just have to include this autoloader in your php file to be able to use all the dependencies and all the namespaces you declared in the autoload section of composer.json.

You can get more infos about composer here : https://getcomposer.org/ You can also browse the available packages here : https://packagist.org/

Hope this will helps

这篇关于PHP Doctrine 初学者:找不到 DoctrineORMToolsSetup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆