Beispiel #1
0
        $field = preg_replace('/^findBy(\\w*)$/', '${1}', $method);
        $query = "select * from " . static::$table . " where {$field} = '{$args['0']}'";
        return self::createDomain($query);
    }
    private static function createDomain($query)
    {
        $klass = get_called_class();
        $domain = new $klass();
        $domain->fieldvalue = array();
        $domain->select = $query;
        foreach ($klass::fields as $field => $type) {
            $domain->fieldvalue[$field] = 'TODO: set from sql result';
        }
        return $domain;
    }
}
class Customer extends ActiveRecord
{
    protected static $table = 'custdb';
    protected static $fields = array('id' => 'int', 'email' => 'varchar', 'lastname' => 'varchar');
}
class Sales extends ActiveRecord
{
    protected static $table = 'salesdb';
    protected static $fields = array('id' => 'int', 'item' => 'varchar', 'qty' => 'int');
}
Customer::findById(123)->select;
Customer::findById(123)->email;
Sales::findById(123)->select;
Sales::findByItem('item')->select;