direct-solution / solution-orm
该软件包最新版本(dev-master)没有提供许可证信息。
SolutionORM,基于NotOrm的现代化版本。
dev-master
2017-03-02 16:15 UTC
This package is not auto-updated.
Last update: 2024-09-26 00:09:29 UTC
README
要求:PHP 5.3+,支持PDO的任何数据库(已测试MySQL、SQLite、PostgreSQL、MS SQL、Oracle)
用法
-
将以下内容添加到您的 composer.json 文件中
"require": {
"direct-solution/solution-orm" : "dev-master"},
-
在您的项目中创建一个Base Model类,如下所示
<?php namespace SolutionMvc\Model; use PDO; /** * Description of BaseModel * * @author doug */ class BaseModel { /** * @var null Database Connection */ public $db = null; public $orm = null; /** @var string */ private $tableName; /** * @var null Model */ public $model = null; /** * Whenever controller is created, open a database connection too and load "the model". */ function __construct() { $this->openDatabaseConnection(); $this->tableName = $this->tableNameByClass(get_class($this)); } /** * Open the database connection with the credentials from application/config/config.php */ private function openDatabaseConnection() { $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING); $this->db = new PDO(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=' . DB_CHARSET, DB_USER, DB_PASS, $options); $this->orm = new \SolutionORM\SolutionORM($this->db); } /** * Determine table by class name * @param string * @return string * @result:Pages => pages, ArticleTag => article_tag */ private function tableNameByClass($className) { $tableName = explode("\\", $className); $tableName = lcfirst(array_pop($tableName)); $replace = array(); // A => _a foreach (range("A", "Z") as $letter) { $replace[$letter] = "_" . strtolower($letter); } return strtr($tableName, $replace); } }
此部分需要完成...