我正在构建一个重用和简单的ORM库; 一切都很顺利,除了我被一个愚蠢的继承限制所困扰.请考虑以下代码:
class BaseModel {
/*
* Return an instance of a Model from the database.
*/
static public function get (/* varargs */) {
// 1. Notice we want an instance of User
$class = get_class(parent); // value: bool(false)
$class = get_class(self); // value: bool(false)
$class = get_class(); // value: string(9) "BaseModel"
$class = __CLASS__; // value: string(9) "BaseModel"
// 2. Query the database with id
$row = get_row_from_db_as_array(func_get_args());
// 3. Return the filled instance
$obj = new $class(); …Run Code Online (Sandbox Code Playgroud) 有没有办法让我可以通过我所在的模型使用当前数据库表?我看到Laravel/Database/Eloquent/model.php中有一个table()函数,但是我调用它从我所在的模型中调用它是不成功的.