wakers / nette-propel2
Nette 2.4 的 Propel 2 ORM 集成,带 Tracy 调试面板
0.9.4
2019-06-19 20:55 UTC
Requires
- nette/di: ^2.4
- propel/propel: ^2.0@alpha
- symfony/console: ^4.1
- symfony/dotenv: ^4.2
- tracy/tracy: ^2.5
This package is auto-updated.
Last update: 2024-09-20 09:16:30 UTC
README
Nette 2.4 的 Propel 2 ORM 集成 带 Tracy 调试面板。
安装
-
使用
composer require wakers/nette-propel2:v0.9
安装此 nette-extensions -
在您的应用程序中注册此扩展
config.neon
extensions: wakers-propel: Wakers\Propel\DI\PropelExtension
-
在
./app/config/db.local.neon
中添加 propel 配置文件wakers-propel: propel: general: project: Wakers CMS 5 version: 5 database: connections: wakers_cms: adapter: mysql classname: Propel\Runtime\Connection\ProfilerConnectionWrapper dsn: 'mysql:host=mariadb;dbname=wakers_cms_db' user: root password: root attributes: settings: charset: utf8 runtime: defaultConnection: wakers_cms connections: - wakers_cms generator: defaultConnection: wakers_cms connections: - wakers_cms tablePrefix: wakers_ dateTime: dateTimeClass: \Nette\Utils\DateTime paths: schemaDir: './app/schema' outputDir: './app/schema' phpDir: './app/schema/model' migrationDir: './app/schema/migration' sqlDir: './app/schema/sql' reverse: connection: wakers_cms migrations: tableName: 1_propel_migration
示例
创建模式
<database name="wakers_cms" namespace="Wakers\Module" defaultIdMethod="native" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xsd.propelorm.org/1.6/database.xsd" > <table name="book" namespace="MyModule\DB" package="./book/"> <column name="id" type="INTEGER" required="TRUE" primaryKey="TRUE" autoIncrement="TRUE"/> <column name="name" type="VARCHAR" required="TRUE" size="64"/> <unique> <unique-column name="name"/> </unique> </table> </database>
使用命令
命令与官方相同,但无别名。
# Compare DB with schema (eventually create migration) ./vendor/bin/wpropel migration:diff # Run migration ./vendor/bin/wpropel migration:migrate # Create model classes ./vendor/bin/wpropel model:build # Show all allowed commands ./vendor/bin/wpropel
创建 PHP 代码
$con = Propel\Runtime\Propel::getConnection(); $con->beginTransaction(); try { $book = new Wakers\Module\MyModule\Book; $book->setName('Any book name'); $book->save(); // Do something else $con->commit(); } catch (Propel\Runtime\Exception\PropelException $exception) { $con->rollBack(); } $books = Wakers\Module\MyModule\BookQuery::create()->find(); foreach ($books as $book) { bdump($book->getName()); }
关于 Propel 2
在开始之前,请考虑使用 Propel 2,因为实际上 Propel 2 已不再维护。
如果您仍然想在 Nette 中使用 Propel2,此扩展是正确的方式。
我们欢迎拉取请求和问题。