Using Agile Toolkit in a very minimalistic way

Normally Api uses some logic to determine which Page class to use, initializations and rendering, but these concepts introduced by ApiWeb can be clearly avoided if you are using ApiCLI class. An example could be creating an execute-once service-type applications which you might want to call directly.

Create a new file demo.php inside the root folder of your Agile Toolkit local installation containing the following:

include 'atk4/loader.php';

$api=new ApiCLI('sample_project');

Model_Employee extends Model_Table {



$mail $this->add('TMail');


"sending to ".$user->get('email').'<br/>';

// $mail->send($user->get('email'));


$user $api->add('Model_Employee');
$user->getRows(array('id')) as $row){



Agile Toolkit's loader adds "lib" and "atk4/lib" directory into your INCLUDE path and enables a simple class auto-loader. This is usually sufficient to find your API class definition. When Application class is loaded, it initializes much more powerful Application Controller called PathFinder, which can then be used to locate the classes.

Notice that examples does not refer to $this, but uses $api instead. This is because example does not belong to any class and runs outside of class context.

Class definitions

When class is used prior to defining, application attempts to include it automatically. However we can still define classes inside our "demo.php" file which makes them available right away. Class definition relies on "Model_Table" which resides under atk4-addons and for that reason must be placed after our extra location is added to pathfinder.

Our model defines a very simple Employee entity, whom we would need to greet in the first work-day morning.

Thick Models

A good MVC practice would always encourage you to keep business logic inside the Model. For this reason we are defining email greeting inside the model itself.


Initialization of a database and any further checks which you would normally put inside init() method of your API can also be defined here. Note that we can't use any visual classes (Views) because rendering infrastructure is not implemented in ApiCLI, but in this case it's not needed anyway.

We can still use TMail class which relies on SMlite to generate and send emails.

Keep it clean

We might need to loop through large database of employees and while adding objects is simple, they will actually pile up in the memory. To keep things clean we are creating new object for each new email we are sending an destroying object when it is no longer needed.

Other purposes

In this example, we send out emails, but a very similar application structure can handle job processing queues and much more complex tasks either run manually or through a cron scheduler.

Database Structure

CREATE TABLE `employee` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `is_greeted` enum('Y','N') DEFAULT NULL,
  PRIMARY KEY (`id`)
  (1,'John Smith','','N'),
  (2,'Peter Falcon','','Y'),
  (3,'Joe Blogs','','N'),
  (4,'Mathew Taylor','','N');

Mail template (templates/mail/greeting.txt)

<?subject?>Welcome to our company<?/?>

Dear, <?$name?>

We love to see you as a member of our team! I hope you will
find your first day exciting!