<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends Application
{

	function __construct()
	{
		parent::__construct();
	}

	/**
	 * Homepage for our app
	 */
	public function index()
	{
		// this is the view we want shown
		$this->data['pagebody'] = 'homepage';

		// build the list of authors, to pass on to our view
		$source = $this->quotes->all();
		$authors = array ();

		foreach ($source as $record)
		{
			$authors[] = array ('who' => $record['who'], 'mug' => $record['mug'], 'href' => $record['where']);
		}
		$this->data['authors'] = $authors;

		$this->render();
	}

	public function random()
	{
		// this is the view we want shown
		$this->data['pagebody'] = 'homepage';

		// build the list of authors, to pass on to our view
		$source = $this->quotes->all();
		$authors = array ();

		$randomIndex = rand(0, count($source) - 1);
		$record = $source[$randomIndex];
		$authors[] = array ('who' => $record['who'], 'mug' => $record['mug'], 'href' => $record['where']);
		$this->data['authors'] = $authors;

		$this->render();
	}


}

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends Application
{

	function __construct()
	{
		parent::__construct();
	}

	/**
	 * Homepage for our app
	 */
	public function index()
	{
		// this is the view we want shown
		$this->data['pagebody'] = 'homepage';

		// build the list of authors, to pass on to our view
		$source = $this->quotes->all();
		$authors = array ();
		foreach ($source as $record)
		{
			$authors[] = array ('who' => $record['who'], 'mug' => $record['mug'], 'href' => $record['where']);
		}
		$this->data['authors'] = $authors;

		$this->render();
	}

}

--- 
+++ 
@@ -21,6 +21,7 @@
 		// build the list of authors, to pass on to our view
 		$source = $this->quotes->all();
 		$authors = array ();
+
 		foreach ($source as $record)
 		{
 			$authors[] = array ('who' => $record['who'], 'mug' => $record['mug'], 'href' => $record['where']);
@@ -30,4 +31,22 @@
 		$this->render();
 	}
 
+	public function random()
+	{
+		// this is the view we want shown
+		$this->data['pagebody'] = 'homepage';
+
+		// build the list of authors, to pass on to our view
+		$source = $this->quotes->all();
+		$authors = array ();
+
+		$randomIndex = rand(0, count($source) - 1);
+		$record = $source[$randomIndex];
+		$authors[] = array ('who' => $record['who'], 'mug' => $record['mug'], 'href' => $record['where']);
+		$this->data['authors'] = $authors;
+
+		$this->render();
+	}
+
+
 }
Add random() function to allow displaying of one random quote author.

Signed-off-by: Wilson Lau <51ca10b964eb3f90521acbc5ab4d054ef62a94b4@gmail.com>
