Rendering content at the client side
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.
Getting ready
First of all, create a fresh Yii application using
yiic webapp.Create a database. Adjust the
dbsection ofprotected/config/main.phpconfiguration 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
Taskmodel.As a client-side template engine, we'll use an excellent
doTlibrary available at http://olado.github.com/doT/. It has easy to learn...