picorm / picormsilexserviceprovider
为 PicORM 提供的 Silex 服务端
dev-master
2013-12-31 12:44 UTC
Requires
- php: >=5.4.0
This package is auto-updated.
Last update: 2024-09-08 10:08:17 UTC
README
将 PicORM 和 Silex 结合,快速构建强大的应用程序
用法
注册提供者可让您完全访问 PicORM,同时也允许您通过 $app['db']
访问 PDO 实例。
use Silex\Application; use Symfony\Component\HttpFoundation\Request; use PicORM\Silex\Provider\PicORMServiceProvider; $config = array( 'picorm.database' => 'databasename', 'picorm.server' => 'localhost', 'picorm.username' => 'user', 'picorm.password' => 'pass' ); $app = new Application(); /* CREATE TABLE IF NOT EXISTS `brands` ( `idBrand` int(11) NOT NULL AUTO_INCREMENT, `nameBrand` varchar(100) NOT NULL, `noteBrand` float DEFAULT 0, PRIMARY KEY (`idBrand`) ) ENGINE=InnoDB ; */ class Brand extends \PicORM\Model { protected static $_tableName = 'brands'; protected static $_primaryKey = "idBrand"; protected static $_relations = array(); protected static $_tableFields = array( 'nameBrand', 'noteBrand' ); public $idBrand; public $nameBrand; public $noteBrand; } $app->register(new PicORMServiceProvider(), $config); $app->match('/index.html', function(Request $request) { var_dump($app['db']); // PDO instance // you can now access to models $brands = Brand::find(); $brand = new Brand(); $brand -> nameBrand = 'brand1'; $brand -> noteBrand = 5; $brand -> save(); }); $app->run();
##许可证
LGPL 许可证