Sneak Peak into Agile Toolkit 4.2

Thursday, November 3rd, 2011|Brainstorming, Core changes, Verison 4.2, Version 4|by Romans

As we nearing our deadline fro 4.2 release a lot of cool features have been added into development branch of Agile Toolkit such as:

  • Completely new “TMail” implementation
  • Completely new “DB” implementation based on PDO
  • Completely new “DSQL” implementation
  • Completely new “Model” implementation
  • Completely new SMlite implementation
  • Improvements in Site Debugging

The new implementations are functionally compatible with the 4.1 branch, although the do offer a number of benefits. In this article, I’ll highlight some of the new features about the new component implementation.

Another important feature of all the new modules is that they are are under heavy automated testing from the very start.

What’s new in the “TMail 2.0″

The TMail class actually been pushed into 4.1.3 release adds much more modularity as well as support for transports. Previously TMail would only send out emails through the mail() function, now it could be written into database, sent over Amazon SES, mail() or any combination of these.

There are also number of improvements in how TMail manages templates – it allow both HTML and Text part to be defined in your template and will automatically produce non-HTML version if you supply with the HTML only.

What’s new in DB implementation

Actually there is nothing new in the DB as compared to “DBlite”. You initialize database by calling $api->dbConnect() and it’s going to stay this way. To use the new database driver you would need to supply the “pdo” in the $config file.

DB implementation features a “query cache”, if a query is executed multiple times, it is prepared only once. This actually makes a lot of sense when you operate with models and parametric values.

What’s new in DSQL implementation

DSQL has been rewritten, but the fundamentals are the same. You create dsql() instance then call methods such as “field()”, “where()”. The new version is much more consistent about escaping arguments and handling of expressions. The new implementation completely relies on parametric nature of PDO, which proved to be a little more challenging to implement, but the interface have not been changed.

1. where(‘id’,2);                    // equals
2. where(‘id’,'>’,2);                // explicit condition
3. where(array(‘id’,2),array(‘id’,3));    // or
4. where(‘id’,array(2,3));           // in
5. where($dsql,4);                   // subquery
6. where(‘id’,dsql);                // in subquery
7. where($dsql->expr(‘length(name)’),123);      // expressions

The new are expression and sub-qureies, and DSQL does a great job figuring out all the parametric queries as you wildly join tables. Dsql now support iterators and the following syntax is permitted:

foreach($q as $row){
echo implode(‘,’,$row)."\n";

What’s new in Model implementation

It has become much simpler and modular. Also I’m adding implementation of interfaces which makes it possible to access active-record in a super-easy way. Here is an example of model use in 4.2 which implements Iterators and ArrayAccess:

foreach($this->add(‘Model_Books’)->addCondition(‘price<’,20) as $book){
$author = $book->getRef(‘author_id’)->sendNotification();
echo $book['name']." by ".$author['name']."\n";

Additionally field implementation is now implemented as number of classes, not just a single “FieldDefinition” class.

$model->addExpression(‘age’)->calculated(function(){ return ‘years(now())-years(birthday)’; });

In all 3 cases the field is defined by a different class which defines how the field is being queried. “Model_Table” is now implemented on top of “Model” class which is a very simple implementation of a model without data-source. This base class can be further extended to allow storing model data in No-SQL storage. Caching could also be further added through controllers.

Models have also some of their methods renamed shorter. Long version will continue to work throughout 4.2, but the use of shorter version is recommended.




Models will also support proper joins in which you could define how new entries are being added.

The way how Models interact with Views and Controllers will be different. Currently $view->setModel(‘abc’) initializes controller first and then initializes model. In 4.2, model is initialized first and placed inside $view->model() and then controller is initialized which imports fields into a form or grid. As a result, you will be able to use Models with “Form” and “Grid” classes, without the need for “MVCForm” and “MVCGrid”

This makes it possible to do many really interesting things for example create Form presenting fields from multiple models.

Also “reference” field is no longer needed as models can be used with “dropdown”.

SMLite improvements

The implementation of our Template Engine is really old but works well. It relies on explode()ing string into chunks then iterating through them. The new SMlite implementation will rely on regular expressions and will perform faster. Currently there are some technical issues with regular expressions, but I hope to overcome them before next release. There will be no new features for the template engine, I intend to keep it simple.

Other improvements and Debug

Overall the migration to use exception() method for raising exceptions proves to be quite rewarding. Errors now contain more useful information and are ready to be localized.

While in debug mode, it will be possible to extract additional information from your current errors. For instance if exception is raised inside Model, it adds a link to error message allowing you to reload the page with model’s debug enabled. This way you don’t need to add $m->debug() manually to spot the problem.

Additionally debugger will allow you to dump a complete tree of all the objects in the system highlighting the problem branch which produced an error.

On the user-interface side, the started installation of Agile Toolkit will feature a simple “inspector” so that you could visually see and understand your code as you start with Agile Toolkit, very similarly to

Changes into atk4-addons

I plan to discontinue atk4-addons repository and instead make those addons loadable and installable through a web interface. The initial package of Agile Toolkit will allow you to browse addons library and install them individually with a mouse click. Addons would be installed into atk4-addons folder.

Documentation and Testing

One of the reasons why DSQL, SMlite and Models are currently lacking in documentation is because I am not satisfied with their internal implementation and was planning to re-implement them for 4.2. I am planning to have our own “Documentation Viewer” and “Testing Engine” as downloadable add-ons as well as having the documentation available for you in off-line format as some users have been requesting.

More importantly you will be able to enhance documentation and test scripts with your own as your application grow in scale.


I’m looking forward to the 4.2 release this winter. As I have already mentioned, Agile Toolkit release cycle produces new major version once every half year. The version is compatible with previous release, however if you do run into some compatibility problems you can still use old TMail, SMlite or DBlite/Models.

Throughout the minor releases any changes are backwards compatible with the use of “Contoller_Compat” class.

Many thanks for your continued interest in Agile Toolkit and I hope you are as excited about new changes as I am.


Posted November 4, 20118:37 am

implementation of ArrayAccess is lovely.

not really sure about “click & install” for add ons, but, probably it would be better that putting all add ons in one basket. + that could open doors for commercial add ons as well.

The Elter
Posted November 4, 201110:00 am

With the new Model implementation is possible to have calculated fields in php (not clculated by sql) ?

Posted November 4, 20111:35 pm

@The Elter, yes.

Posted December 3, 20119:57 pm

Very impressive. Tks.
Unfortunately I would have to access MSSQL-DB.
How should I do that ? Any chance to use classes like CRUD or GRID based on an other DB-connection ?

Posted December 4, 20119:31 am

I would love if you could help me test the new up-coming 4.2 version on mssql. If you have left your email during download of Agile Toolkit, you will be sent an invitation.

Posted December 4, 201110:35 am

Please ! (although beginner in PHP) Tried for long to get into web development (coming from the .NET-world) and finally feel at home with your approach: logical concept, easy to understand, quick results, focus on business logic – not technical details, full flexibility if needed (my guess). Great Job !

Posted December 4, 201110:37 am

Thanks, Love your feedback!

Posted June 1, 20122:14 pm

I also have some projects that could benefit from being connected to MSSQL. Is the MSSQL DB connector available to try out?

Posted June 2, 20127:23 pm

Hi Joe.

Agile Toolkit uses PDO so it should work with MSSQL out of the box. If you find that any queries are not working properly, cerate DB/mssql.php class in your local lib/ folder and adjust templates as necessary. You can ask questions in the Agile Toolkit Developer group.