Agile Toolkit for CodeIgniter developer

Wednesday, August 31st, 2011|Beginner tips, Brainstorming, Version 4|by Romans

Welcome to the series of posts which helps you understand Agile Toolkit if you are coming from one of the other PHP Frameworks.

This post focuses on developers who are already familiar with CI (Code Igniter) and are willing to try Agile Toolkit.

I’d like to start by saying that CodeIgniter is a great framework. It does things it’s supposed to very well and it’s a great contribution to the PHP community.

Agile Toolkit is very different to Code Igniter. The biggest difference is User Interface. When you develop in CI, you manage your “views” in any way you like. You are responsible for building HTML template and for putting it together from controllers. Agile Toolkit not only provides you with the “framework” or the base structure of the application, but it also contributes a lot of visual elements to your development workflow. That’s why it’s named “Toolkit”.

CI:Front Controller -> ATK:Page

In Code Igniter, when request is executed, it gets automatically handled by the application through mod-rewrite. Application relies on a set of routes to determine, with controller should handle the request.

Agile Toolkit performs similarly, but uses different terminology. Application does not do any advanced routing, your URL maps to the Page. Agile Toolkit uses GET arguments, where CI uses routes. After the routing, request in Agile Toolkit hits the Page object. Page is similar to Controller in the way how it defines what must be do. The term “Page” very strongly explains what class is doing – it implements a single page on your website or web application.

Agile Toolkit supports concept of sub-pages, which allows you to consolidate multiple pages into a single class. By naming respective functions “page_XX” you can avoid any security issues from public methods being accessible through web.

Role of CI:Controller and ATK:Page are different. CI:Controller is supposed to return HTML. ATK:Page on other hand only initializes objects tree. Those objects are later rendered by API.

CI:Views -> ATK:Templates

CI refers to views to a files which contain markup and some PHP logic. Agile Toolkit philosophy promotes strong separation of templates and logic. Agile Toolkit have a standard template engine, which is very lightweight and can only define tags and manipulate them similarly to DOM methods.

In Agile Toolkit you can safely let designer edit the templates. Templates also tend to be more generic and they are recursive. For example you could have template for “sidebar”, “preferences box”, and “button”. Sidebar would contain preferences box which might have couple of buttons. Templates are never used on their own, they are always coupled with Objects (ATK:Views).

In CI views may contain other views, but because all the properties are injected from controller, you would need to anticipate what’s inside.

CI:Helpers -> ATK:Views

In CodeIgniter helpers implement things like Form, BreadCrumb, QuickSearch and so on. They might have very specific structure and requirements. In Agile Toolkit, views are everywhere. Page class and even API is inherited from View. View is any object capable of producing HTML output.

The structure of Views is much deeper in Agile Toolkit. Each view also have a default template, which you can re-define when you add view. In Agile Toolkit you can add views into another views even in the most unpredictable ways. For example you can add button inside the field of a form. This ability will also apply to any user-designed views.

All the views in Agile Toolkit work in 3 phases. Adding, initializing and rendering. Adding will position view inside a parent view and define where it will render itself. Initialization will customize the view such as adding fields to the form or columns to a grid. Finally, during rendering, the data is fetched and heavy-duty tasks are done.

All standard views in Agile Toolkit would automatically assign “id” property to their HTML code which is used for integration with jQuery.

CI:Library -> ATK:Controller

In Agile Toolkit controllers are used for many different things. By definition, controller is extending functionality of the object, where you add it. For example, you can add “Controller_SEO” to your application, which will ability to tweak properties needed for search engine optimization.

Controllers fall into different categories depending on where you can add them. Some are quite universal. For example “Order” controller allows you to re-order sequence of children elements inside any object. Other controllers only work with a single type of class. For example encryption controller works with models.

While in CI libraries would normally be instantiated only once, Agile Toolkit allows to create multiple controllers as long as you add them into different objects.


In Agile Toolkit there are several application classes, ApiCLI, ApiWeb, ApiFrontend and so on. When you build your application, the first thing you do is extend one of API classes into your own Frontend class. In the future you can learn to build intermediate application classes as well.

The difference between different API classes is about what controllers they add by default. Application can be referenced from any object in the system through $object->api.

It is possible to create multiple applications in memory, for example if you want to perform call specific to “Frontend” from “Admin” backend, such as authenticate as user of your choice. This is done simply by adding the proper Application class.

Agile Toolkit uses no global variables, contents or definitions, therefore multiple application instances will not conflict.


The reason for having models in Agile Toolkit is different to CodeIgniter. Models in Agile Toolkit defines business entities. Models would often inherit each-other – User, Publisher, ExpiredPublisher. By relying on each-other models can add additional conditions, additional fields or join with additional tables.

Model in Agile Toolkit is like a combination of SQL:View and stored procedures, only in the language you can actually use. When operating with Model, it will restrict you to it’s own conditions. It may combine multiple tables inside itself. It can also perform multi-record queries through the use of DSQL language.

Dynamic Queries

CodeIgniter allows you to avoid SQL by calling functions such as “where”, “order” on a DB object and constructing queries. The same is done by Agile Toolkit’s DSQL class. The difference is that you can have multiple instances of DSQL class, while CI is designed to have only one. DSQL in Agile Toolkit are integrated into many views making it easy for you to affect what they display. Models also are based on DSQL.

When you create Grid view and use it with Model, then they share the same DSQL. Any conditions defined in model will also apply on Grid.


There are no interface in Code Igniter, but Agile Toolkit comes with the standard user interface. As you create buttons, you do not worry about their look, which is defined through a theme.  Interface in Agile Toolkit uses jQuery UI CSS framework and Flexible Grid System.

Approach to JavaScript

CodeIgniter offers only minimum capabilities of including JavaScript files. Agile Toolkit comes with it’s own JavaScript API layer, which fills many gaps between jQuery and server side, such as time-outs, loading visual feedback, multiple submits, session expiration, dynamic include loading and many other things. All of this can be flexibly extended and comes as a base which means any web application with Agile Toolkit can take advantage of this API.

Agile Toolkit also introduces ability to use PHP language to bind actions on objects. It helps to properly encode the data as you execute your own JavaScript functions.

Approach to AJAX

CodeIgniter like many other frameworks require you to carry out scripting separate from the backend. You can use back-end to retrieve data in the format you like, such as JSON.

In Agile Toolkit, you do not need to write any JavaScript to use AJAX. JavaScript API in Agile Toolkit uses “reloading” technique with allows any segment of the page to be reloaded anytime. You can bind that on buttons, execute this from form submit or on other conditions. This does transfer slightly more data from backend into frontend, but you get the benefit of not writing any JavaScript, having consistent performance of your AJAX and many other benefits such as automated dependency checking and dynamic widget loading.

Agile Toolkit also makes use of “evaluating” AJAX response. For example, when you submit the form, data is being sent through AJAX request. Server responds with JavaScript code which is evaluated by form widget. That have many advantages over JSON or JSONP as it is much more universal and UI can be fully controlled from backend. It also allows to execute multiple actions.

Approach to directory structure

Code Igniter has a very well defined structure – system, libraries, application, etc. Agile Toolkit is more flexible about the structure and instead of telling you what to do and how, it simply sits inside “atk4″ folder and defines some of the basic locations for your application resources. As you develop more complex applications which need to share code, you can introduce shared resources or pull in some addons which can also have their own resources.

By default with Agile Toolkit you put your code inside page/, lib/, templates/ and the library code which you shouldn’t change sits inside atk4/lib, atk4/templates.

Overriding Classes

Code Igniter allow you to substitute base class with your own. For example you can create MY_Application which will replace and extend CI_Application. In Agile Toolkit you can do the same thing with some class such as Page, Grid, Form. Agile Toolkit uses concept of “pushing” default resources away as you introduce your. This way you can create any file inside your local directory which will be used instead of the one inside atk4 folder. Some classes in atk4 are intentionally left transparent. Class Grid extends Grid_Basic {}.

This allows us to use “Grid” class in all tutorials and samples, but you can still re-define this class without loosing any of the functionality.

Constructors and Instances

With CodeIgniter you quite often find the need to define object constructors. In Agile Toolkit you never override default constructor. Instead there is a function init() for all object which you should use.

There are no static classes in Agile Toolkit. You also never use “new”, only “add”.


If you compare performance of Agile Toolkit with CI on the very basic “Hello World” level, it would be very comparable. As you add more views and UI elements, Agile Toolkit has some overheads. Still the code is much lighter than GWT, ExtJS or Cappuchino frameworks. You as developer can also customize templates to your liking.

Regular UI page would have no speed impact and would allow to produce around 10-100 requests per second without caching.

It’s also true that if you build standard User Interface on top of Code Igniter with comparable features, the theoretical performance of Code Igniter would be much worse. Agile Toolkit’s UI is hardwired into it’s core and heavily optimized.

When to move from CI to Agile Toolkit?

You should certainly move if you want to get usable interface faster. It’s also a good idea to use Agile Toolkit if you expect a lot of AJAX in your application.

Overall Application written in Agile Toolkit are more flexible, easier to install and much easier to understand. Typical application in Agile Toolkit will have significantly less lines of code than Code Igniter.

If you are good with Code Igniter and I have made any mistakes in this article, please point to in the comments.


Posted September 1, 20116:22 am

Yeah! Nice one. Keep series going. This would finally let users understand where ATK really stands. Good work. We need YII next in the series.

Posted September 1, 20119:59 am

I am not very good with Yii, have you developed using it? People love it and it’s certainly step in the same direction Agile Toolkit is going.

Posted September 20, 20117:47 am

Great article. I am already interested to try Agile Toolkit.I like the idea of adding views and UI elements.I also like the entire development model and i think that if you add enough functionality to the design/architecture,this would allow developers to work easy and fast.In my opinion the some of the architectural decisions provides features which are close to .Net strong points.

Posted September 20, 20118:11 am

I absolutely agree, the_oak. I have already few people who shared their plans to build tools on top of Agile Toolkit. Form builder is a joke which you can make to raise some money by competing with other PHP form builders, for example.