orm Object Relational Mapping
对象关系映射php
laravel 中我认为最好用的莫过于 orm tp3.2 中也有相似的东西,可是使用起来老是感受很费力,多是先入为主的缘由吧。laravel
可是为了提高开发速度和减小使用 tp3.2 的不适感,如今来把 laravel 中的 orm 接入到 tp3.2 中git
为何说是接入呢?
由于 laravel 的 orm 是能够单独使用的详见github
illuminate/database
感谢组件化开发,感谢 composerjson
到 这里 选择合适的版本app
composer require illuminate/database // or for php 5.5.9 composer require illuminate/database:5.2.*
依然保持 index.phpcomposer
require 'vendor/autoload.php';
Thinkphp/Library/Think/Think.class.php 中的 start() 方法中的 App::run() 以前添加 // ORM $capsule = new \Illuminate\Database\Capsule\Manager; $capsule->addConnection([ 'driver' => C('DB_TYPE'), 'host' => C('DB_HOST'), 'database' => C('DB_NAME'), 'username' => C('DB_USER'), 'password' => C('DB_PWD'), 'charset' => C('DB_CHARSET'), 'collation' => C('DB_COLLATION'), 'prefix' => C('DB_PREFIX'), ]); $capsule->setAsGlobal(); $capsule->bootEloquent();
为了能够加载 App/Models 下的文件在 composer.json 中组件化
"autoload": { "files": [ "App/helpers.php" ], "psr-4": { "App\\": "App" } }
而后就能够想 laravel 中的 orm 同样使用了ui
这时是不能使用 paginate 的要想使用code
composer require illuminate/pagination
同时注意选择对应的版本