Hello guys.
Last night in about 22:00 (European time), I’ve wanted to write my own ORM with simple save and update functions and find by PK, Attributes, SQL and to have methods for more results, like in Yii: findAllBySql, findAllByAttributes, etc.
I wrote that thing in about 4 hours. Then I was messing around with .htaccess and rewriting URL’s, and I’ve created a small router with single-request-controller (i.e. /about, /index, /etc) with no sub-action/action support currently.
When I’ve done that, I’ve realized that I have Model-Controller system, then I’ve just created a Renderer class witch will do the basic rendering.
I’m posting this as an example of my code and work I’ve done in 9 hours straight! This code is available on GitHub:
(since this is my first post, the link will be posted in my next post in this topic!)
(don’t ask for the branch name - it was my first commit ever there!)
Also, I’ve created a test landing page to see some basic options here.
One thing, I haven’t done the model inheritance like in Yii; but I have done something quite similar, so you’ll create an instance of a model like this:
// new data
$model = new Table(‘users’);
// find data
$model = Table::model(‘users’)->findByPk(1);
And you’ll get your results and you can do updates or inserts with: update() or save() methods built-in into the Models.
Also, I’ve created two rendering methods: render($file, $extractionParams) & renderText($text, $params) - with basic templating functions in the second method.
You’re reviews are quite welcome on any matter of this project.
You will notice that code is quick written and I haven’t commented almost nothing there, and there might be quite much bugs as I was able to discover, so help in that direction might be also useful for me.
PS I used no code from Yii - but I’ve used it as a foundation and basic idea - regardings how models, controllers and views should interact with eachother - and just to say a notice that I use Yii very offten in my projects and it was a lifechanger to me.
Thank you all for your reviews