Loading a block through AJAX
Nowadays, it's common when part of a page is loaded asynchronously, that is, without reloading the rest of the page. Let's implement the quotes box, which will display random quotes and will have the Next quote link to show the next one.
Getting ready
Create a fresh Yii application using
yiic webappas described in the official guide.Configure the application to use clean URLs.
How to do it...
Carry out the following steps:
Create a new controller named
protected/controllers/QuoteController.phpas follows:<?php class QuoteController extends Controller { private $quotes = array( array('Walking on water and developing software from a specification are easy if both are frozen.', 'Edward V Berard'), array('It always takes longer than you expect, even when you take into account Hofstadter’s Law.', 'Hofstadter’s Law'), array('Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where...