Sometimes a website needs to be a bit more dynamic than usual and should work like a desktop application. This is often required for complex user interfaces in cases when response time is critical or when you want to move some load from your server to clients.
In this recipe we'll implement a simple one page "to do" application. It will not reload the page after adding, deleting, or completing tasks. To make it more fun, let's communicate with the server side via REST in pure JSON.
First of all, create a fresh Yii application using
yiic webapp
.Create a database. Adjust the
db
section ofprotected/config/main.php
configuration file to use it.Execute the following SQL:
CREATE TABLE task ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, done BOOLEAN DEFAULT 0 );
Use Gii to generate a
Task
model.As a client-side template engine, we'll use an excellent
doT
library available at http://olado.github.com/doT/. It has easy to learn...