Hello friends.
Sorry for the lack of posting these days. I’ve been working hard on the finishings of the WebTodo project (in Brazillian Portuguese).
This project was a kickstart for my own MVC Framework. As cited in previous article, I was not confortable with the idea of using one of the existing MVC Frameworks because I’m a little paranoid of not having exact (and full) control of my code. The only way to assure quality was from coding every piece.
I’ve started planning which caracteristics it’ll have and which existing solutions I would use (as Peteris says “good coders code, great coders reuse”). I’ve picked up so Smarty Template Engine because I’ve had plenty of previous experiences working with it (and all of them gave me loads of pleasure) and PHP Doctrine ORM after a big study of the major existing ORMs.
Doctrine
As far as I can say working untill now with Doctrine is: the documentation could be way much better – had to use logic and code flow inspection to find how to do some stuff – but its not that bad after all, I’ve had to fix some code in the Searchable behaviour (I’m working with John Wage from Doctrine via the trac on this) and had some minor code issues in model generation from YAML files that we are already working on.
Performance is good after all but I still don’t have so many data load to ensure. Doctrine has a native Profiling (Benchmarking) tool that is just great. The behaviours that comes within the package are one great set of the most useful that you may need: Searchable (Auto-generates an indexing table), Timestampable (timestamps inserts and updates within the registries automatically), Sluggable (creates a web-save name for RESTful use) and you can even create your own (haven’t tested yet).
The gold of Doctrine in my opinion is the ease of database modeling over the YAML files. This is where Propel lost for me: Huge and complex (ok I’m being a little dramatic) XML files just scared me away. With the YAML files you can set the fields, validation type (email, not blank, not null, min_lenght etc) – that Doctrine validates automatically and throw{}s the error exceptions so you can parse at your will -, the behaviours and relations. Just beautiful.
Here’s one of my tables that illustrates the most:
---
Keyword:
actAs:
SoftDelete:
Timestampable:
created:
name: ts
type: timestamp
format: Y-m-d H:i:s
updated:
name: ts_up
type: timestamp
format: Y-m-d H:i:s
Sluggable:
fields: [keyword]
name: slug
type: string
length: 255
Searchable:
fields: [keyword]
columns:
id_keyword:
type: integer(20)
notnull: true
primary: true
autoincrement: true
terms:
type: integer(20)
notnull: true
id_parent:
type: integer(20)
notnull: false
id_category:
type: integer(20)
notnull: false
keyword:
type: string(255)
notnull: true
notblank: true
unique: true
initial:
type: string(1)
notnull: true
notblank: true
search_count:
type: integer(20)
notnull: false
default: 0
relations:
Category:
class: Category
local: id_category
foreign: id_category
foreignType: one
Parent:
class: Keyword
local: id_parent
foreign: id_keyword
foreignType: one
options:
collate: utf8_unicode_ci
charset: utf8Smarty
Smarty is the only templating system that made me assing variables, perform simple conditional and iterational actions in a easy manner. It even allows you to write your own plugins and string modifiers that aided me on the integration of my form inputs with Doctrine’s validation over the whole framework.
Three good plugins born from there:
The atoz plugin that easely creates for me “A to Z” link lists of anything.
The pager that creates the pages links with first, next, previous, last buttons; custom class for the current page; custom link title option and you can choose to show or not the “All” link.
The input. The most complex one that generates my inputs without locking up the default input attributes described at the W3C Input Specification. It handles automatically the errors – refill fields with the posted data, change the classes, show error information div etc – for input, select and textarea.
NOTE: All the plugins generates XHTML code based on SEO practices and web standards.
I’ll be posting them until the end of this week. It’s a little focused on the patterns established by my framework but I’ve efforted to make it very flexible.
The Framework
I’ve used some of the best-practices I’ve watched over the last year (and over my whole coder life) and carefully chosen the ingredients for the “evil-potion”.
Most of them – as expected – came from Rails. The MVC pattern was implemented over – as expected too – my vision of MVC.
Some good pieces of code I took from Akelos PHP Framework (obviously the author comments were left): The Router (that is a really good piece indeed), parts of the Inflector (string manipulation) – the underscorer and the camel case, the Dispatcher idea and some other minor good practices. Akelos is one of the frameworks that I’ve sympathized with. Worth a check!
I’ve used lot of things that I liked in other frameworks like preFilter/postFilter (that runs before and after each action) that helped A LOT under the admin handling. The layout concept, REST, modularization and other stuff were used too.
Wow, that was an extensive month of work! I’ll have to spend good time now writing about the practices and codes that the framework made me feel on my skin.
Regards!