Home

Awesome

Cake Toolkit (CTK)

The Cake Toolkit is a CakePHP plugin designed for medium-to-large scale web applications which require a scalable and standard solution to handling Views.

The plugin allows Views to be defined as a class, providing a powerful object-oriented factory interface to dynamically build your application's UI with configurable objects.

The main features of the plugin include:

To start using the Cake Toolkit it's as simple as including the plugin in your application, and then extending the CtkAppController to inherit everything you'll need, for example:

class ExampleController extends CtkAppController {

	public function index() {
		// action logic
	}
}

Or, alternatively, using the AppComponent for existing controllers:

public $components = array('Ctk.App');

You can then define your View as a class, and build your UI using the objects made available through the included factories, without requiring extensive knowledge of the underlying technologies, for example:

class IndexView extends CtkView {

	public $factories = array('Html', 'Js');

	public function build() {
		// create a HTML div
		$div = $this->Html->Div();
			// create a HTML button
			$button = $this->Html->Button(array(
				'value' => __('Click Me')
			));
			// add an event to the button
			$button->addEvent('click', $this->Js->Alert(array(
				'text' => __('Hello World')
			)));
		// add the button to the div
		$div->add($button);
		// add the div to the view
		$this->add($div);
	}
}

It's also possible to use the special Factory helper to import objects from the Cake Toolkit into normal static ".ctp" Views, bringing the power of the plugin to your existing View code.

public $helpers = array('Ctk.Factory');

You can then use the objects within your markup, similar to when using the HTML helper, for example:

<div id="example">
	<?php echo $this->Factory->Html->Span(array('text' => __('Hello World'))); ?>
</div>

To get up and running quickly check out the Quick Start or Hello World tutorials from the wiki.

Requirements

Documentation

Once installed, the Cake Toolkit has a homepage built into the CakePHP plugin itself. To access the homepage, visit /ctk from your application base, for example:

http://example.com/ctk

Full documentation, as well as tutorials, are also available from the wiki section of this repository.

Performance

As with all modern web applications, performance is an important issue to take into consideration, specially if you're running a large enterprise scale application which has high development and maintenance costs associated with it.

It's important to note that the aim of the Cake Toolkit is not to increase the performance of the View layer in the MVC stack, but to improve the effectiveness of the development, as well as decrease the maintenance required for large scale applications. CakePHP already has very powerful and configurable caching mechanisms available, which are also available to CTK when building your Views, and strongly recommended due to the heavy use of objects by the plugin.

To quickly add caching to your View, simply define the $cacheAction property in your Controller, and define the settings for the actions you wish to cache. For example, with an action called "example", you can define a cache time of 1 week with the following:

public $cacheAction = array(
	'example' => array('duration' => 36000)
);

Packed with the plugin is a Benchmark controller which provides various actions which can be scaled at runtime to view the overall performance impact:

When "debug" is set to any value higher than 0, and assuming caching is NOT enabled, the plugin will also add a Ctk-Info header to the HTTP response, for example:

Ctk-Info: controller=Benchmark, action=single, render-time=0.019, total-memory=6.86MB, memory-usage=1.83MB

This header contains the following values:

The following table shows a basic performance scalability benchmark based on the single action of the Benchmark Controller, without caching enabled:

<table> <tr> <th></th> <th>1 Node</th> <th>10 Nodes</th> <th>100 Nodes</th> <th>1000 Nodes</th> <th>10000 Nodes</th> </tr> <tr> <th>Render Time</th> <td>0.019</td> <td>0.024</td> <td>0.030</td> <td>0.236</td> <td>2.386</td> </tr> <tr> <th>Total Memory</th> <td>6.86 MB</td> <td>6.89 MB</td> <td>7.17 MB</td> <td>10.03 MB</td> <td>38.98 MB</td> </tr> <tr> <th>Memory Usage</th> <td>1.83 MB</td> <td>1.86 MB</td> <td>2.14 MB</td> <td>5.01 MB</td> <td>33.96 MB</td> </tr> </table>

These tests were performed on a Intel Pentium laptop using 4 GB of RAM, with the maximum memory setting of PHP set to 128 MB.

IMPORTANT: Remember that caching is NOT enabled on this controller, as viewing the changes to the action's output is vital to purpose of its use. Turning on the cache for an action of a CTK Controller is almost identical in performance to that of a standard static ".ctp" View, as the plugin uses the same routing for the cached files.

Support

For support, bugs and feature requests, please use the issues section of this repository.

Licence

Copyright 2012 James Watts (CakeDC). All rights reserved.

Licensed under the MIT License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.

Acknowledgements

A special thanks to Larry Masters, the founder of CakePHP, for his help and support, to José Lorenzo for his input early on when I was hacking the framework, to Florian Krämer for his constructive critisism, as well as the entire CakeDC team for their feedback and encouragement.