如何有效地实例化和使用 Propel

How to instantiate and use Propel effectively

好的,我用 Composer 安装了 Propel,我通过 "Easy Way" propel init

设置了它

现在我正在尝试执行此示例,如 Propel 文档中所示:

<?php
/* initialize Propel, etc. */

$author = new Author();
$author->setFirstName('Jane');
$author->setLastName('Austen');
$author->save();

但是没有关于如何正确"initialize Propel"。

尝试过:

use php_orm\php_orm\TblEmpresa;

$empresa = new TblEmpresa();
$empresa->setName('Teste');

但这只会导致错误:Class 'php_orm\php_orm\TblEmpresa' not found in

这似乎是 Propel 初学者反复出现的问题。

这里有一个演示文稿,在整个起床和 运行 推进过程中(使用 "easy way" 和 propel init)。

Up & Running with Propel2 (Presented at OpenWest 2016)

这应该可以帮助您解决您的问题,因为它已经解决了其他几个与您情况相同的问题。如果没有,请随时告诉我。

如其他类似问题所示,此问题已通过描述在 compose.json 中生成 class 的 php 的确切路径解决,例如:

{
    "require": {
    "propel/propel": "~2.0@dev"
},
    "autoload": {
        "psr-4": { "": ""},
        "classmap": [
            "vendor/bin/orm/orm/",
            "vendor/bin/orm/orm/Base/",
            "vendor/bin/orm/orm/Map/"
        ]
    }
}

然后在终端上 运行:

composer update

composer dump-autoload