我安装了propel并希望从http://propelorm.org/documentation/02-buildtime.html测试示例。但是当我想生成SQL代码时,没有任何反应。 我按照下面的描述尝试了它:propel.bat sql:build -verbose
我已将PATH设置为PHP,并将其设置为来自者的\ vendor \ bin。
我想问题是文件\ vendor \ propel \ propel.php和我的testfolder文件propel.php之间的问题。
我使用了以下文件:
Propel.php (我不确定使用propel.php,因为在开头提到的页面上以“”缺失开头)。我试过了。
<?php
return [
'propel' => [
'database' => [
'connections' => [
'bookstore' => [
'adapter' => 'mysql',
'classname' => 'Propel\Runtime\Connection\ConnectionWrapper',
'dsn' => 'mysql:host=localhost;dbname=my_db_name',
'user' => 'propel',
'password' => 'propel',
'attributes' => []
]
]
],
'runtime' => [
'defaultConnection' => 'bookstore',
'connections' => ['bookstore']
],
'generator' => [
'defaultConnection' => 'bookstore',
'connections' => ['bookstore']
]
]
];
Propel.xml
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<config>
<propel>
<database>
<connections>
<connection id="bookstore">
<adapter>mysql</adapter>
<classname>Propel\Runtime\Connection\ConnectionWrapper</classname>
<dsn>mysql:host=localhost;dbname=my_db_name</dsn>
<user>propel</user>
<password>propel</password>
<attributes></attributes>
</connection>
</connections>
</database>
<runtime>
<defaultConnection>bookstore</defaultConnection>
<connection>bookstore</connection>
</runtime>
<generator>
<defaultConnection>bookstore</defaultConnection>
<connection>bookstore</connection>
</generator>
</propel>
</config>
Propel.yaml
propel:
database:
connections:
bookstore:
adapter: mysql
classname: Propel\Runtime\Connection\ConnectionWrapper
dsn: "mysql:host=localhost;dbname=my_db_name"
user: propel
password: propel
attributes:
runtime:
defaultConnection: bookstore
connections:
- bookstore
generator:
defaultConnection: bookstore
connections:
- bookstore
Propel.json
{
"propel": {
"database": {
"connections": {
"bookstore": {
"adapter": "mysql",
"classname": "Propel\Runtime\Connection\ConnectionWrapper",
"dsn": "mysql:host=localhost;dbname=my_db_name",
"user": "propel",
"password": "propel",
"attributes": []
}
}
},
"runtime": {
"defaultConnection": "bookstore",
"connections": ["bookstore"]
},
"generator": {
"defaultConnection": "bookstore",
"connections": ["bookstore"]
}
}
}
Propel.ini
[propel]
;
; Database section
;
database.connections.bookstore.adapter = mysql
database.connections.bookstore.classname = Propel\Runtime\Connection\ConnectionWrapper
database.connections.bookstore.dsn = mysql:host=localhost;dbname=my_db_name
database.connections.bookstore.user = propel
database.connections.bookstore.password = propel
database.connections.bookstore.attributes =
;
; Runtime section
;
runtime.defaultConnection = bookstore
runtime.connections[0] = bookstore
;
; Generator section
;
generator.defaultConnection = bookstore
generator.connections[0] = bookstore
schema.xml中
<?xml version="1.0" encoding="UTF-8"?>
<database name="bookstore" defaultIdMethod="native">
<table name="book" phpName="Book">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="title" type="varchar" size="255" required="true" />
<column name="isbn" type="varchar" size="24" required="true" phpName="ISBN"/>
<column name="publisher_id" type="integer" required="true"/>
<column name="author_id" type="integer" required="true"/>
<foreign-key foreignTable="publisher" phpName="Publisher" refPhpName="Book">
<reference local="publisher_id" foreign="id"/>
</foreign-key>
<foreign-key foreignTable="author">
<reference local="author_id" foreign="id"/>
</foreign-key>
</table>
<table name="author" phpName="Author">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="first_name" type="varchar" size="128" required="true"/>
<column name="last_name" type="varchar" size="128" required="true"/>
</table>
<table name="publisher" phpName="Publisher">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="name" type="varchar" size="128" required="true" />
</table>
</database>
这些文件是从vendor / bin中的propel自动生成的 Propel.bat
@ECHO OFF
SET BIN_TARGET=%~dp0/../propel/propel/bin/propel
php "%BIN_TARGET%" %*
推进
#!/usr/bin/env sh
SRC_DIR="`pwd`"
cd "`dirname "$0"`"
cd "../propel/propel/bin"
BIN_TARGET="`pwd`/propel"
cd "$SRC_DIR"
"$BIN_TARGET" "$@"
和这些在vendor / bin / propel / propel / bin中 推进
#!/usr/bin/env php
<?php
include('propel.php');
propel.bat
@echo off
if "%PHPBIN%" == "" set PHPBIN=php
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "bin\propel" %*
Propel.php
<?php
if (!class_exists('\Symfony\Component\Console\Application')) {
if (file_exists($file = __DIR__.'/../../../autoload.php') || file_exists($file = __DIR__.'/../autoload.php')) {
require_once $file;
} elseif (file_exists($file = __DIR__.'/../autoload.php.dist')) {
require_once $file;
}
}
use Symfony\Component\Console\Application;
use Symfony\Component\Finder\Finder;
use Propel\Runtime\Propel;
$finder = new Finder();
$finder->files()->name('*.php')->in(__DIR__.'/../src/Propel/Generator/Command')->depth(0);
$app = new Application('Propel', Propel::VERSION);
foreach ($finder as $file) {
$ns = '\\Propel\\Generator\\Command';
$r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
$app->add($r->newInstance());
}
}
$app->run();
答案 0 :(得分:0)
我找到了问题的解决方案。我在我的工作文件夹中有太多文件:我有propel.xml,.yaml,.php,.json,.ini和scheme.xml。当我决定采用propel.xml和scheme.xml时,一切似乎都在起作用。