ezrpg-legacy / ezrpg-2.0.X-discontinued-

http://ezrpgproject.net
Other
6 stars 0 forks source link

Move CRUD operations into Base Model #3

Closed uaktags closed 11 years ago

uaktags commented 11 years ago

As per discussion relating to ezRPG\Model and CRUD operations, move all CRUD functions from ezRPG\Models\PDO to ezRPG\Model so that it's accessible to all Models from the get go. Also we need to significantly debloat the CRUD, they were created as a generic package for the Swiftlet community as a whole and don't fully meet our needs.

ghost commented 11 years ago

No need for PDO model, keep that functionality in our base model.

ferdis commented 11 years ago

I should probably inform you too. We're thinking about switching to a better model. At the moment these "models" are basically singletons, without much abstraction or well, data modeling.

I'm going to implement something similar to there following: http://www.zacharyfox.com/blog/php/simple-model-crud-with-php-5-3

From that structure/base, I'll improve some things there(not everything is ideal). The idea is that new models will basically have structures such as defined below, with a hook that will "sync" all models automatically once the controller has been destroyed. Within a controller, the models will be bound to the instantiated object itself, under something like $this->player or something similar. Other models will have to be retrieved via a get method or something similar.


class Player extends Model {

    protected $id;
    protected $username;
    protected $password;
    protected $email;

    public function getEmail() {
        return $this->email;
    } 

    public function setEmail($email_address) {
        $valid_email = filter_var($email_address, FILTER_EMAIL);

        if ($valid_email != true) {
            throw new InvalidParamaterException($email_address .' is not a valid email address');
        }

        $this->email = $email_address;
        return true;
    }
}

Within the base model, you'll then, for convieniance, have something like this:


    public function __set($key, $value) {
        $method = sprintf('set%s', ucwords($key));
        if (in_array($method, get_class_methods($this))) {
            call_user_function(array($this, $method), $value);
        } elseif (property_exists($this, $key)) {
            $this->$key = $value;
        } else {
            throw new InvalidKeyException($key . ' refers to an undefined key');
       }
   } 
uaktags commented 11 years ago

Wondering how development is going on this issue?

ferdis commented 11 years ago

Ohh yes, I forgot about this... I'll implement a prototype this weekend and push it to a branch. — Sincerely Ferdi Schmidt

On Fri, May 24, 2013 at 9:08 AM, uaktags notifications@github.com wrote:

Wondering how development is going on this issue?

Reply to this email directly or view it on GitHub: https://github.com/uaktags/Rework-Revisited/issues/3#issuecomment-18389727