20
Ushahidi 101 •Setting up a development environment •Introduction to MVC and the Kohana (PHP) framework •Working with GIT

Intro to Ushahidi for Developers

Embed Size (px)

DESCRIPTION

Intro to Ushahidi for developers. Prepared by Wilfred Mworia and Linda Kamau - Ushahidi Devs.

Citation preview

Page 1: Intro to Ushahidi for Developers

Ushahidi 101

•Setting up a development environment•Introduction to MVC and the Kohana (PHP) framework•Working with GIT

Page 2: Intro to Ushahidi for Developers

Setting up: Prerequisites

• MySQL• PHP 5• Apache

Page 3: Intro to Ushahidi for Developers

Setting up: Code

• Download and Install GIT (more later)– http://git-scm.com/download

• Clone (‘Checkout’) the code– cd [WORKING DIRECTORY]– git clone 

git://github.com/ushahidi/Ushahidi_Web.git• Fire up editor (e.g. Zend) and set up a new project from existing code

Page 4: Intro to Ushahidi for Developers
Page 5: Intro to Ushahidi for Developers

Setting up: Database

• Create a database in mysql called 'ushahidi'.• Run USHAHIDI_ROOT\sql\unshahidi.sql against DB

• Go to USHAHIDI_ROOT\application\config\database.php and edit the user, database and host configurations.

Page 6: Intro to Ushahidi for Developers

What is MVC?

• Model-View-Controller

• Separates:–M: Data model

– V: Presentation (UI)

– C: Business logic

• Can change any of these three without affecting the others (in theory)

Page 7: Intro to Ushahidi for Developers

What is MVC?

• A Model represents a data structure, usually this is a table in a database.

• A View contains presentation code such as HTML, CSS and JavaScript.

• A Controller contains the page logic to tie everything together and generate the page the user sees.

Page 8: Intro to Ushahidi for Developers

Why use an MVC framework?

• Avoid “reinventing the wheel”

• Use proven, tested code

• Automation (ORM, generators)

• Maintainability

• “Plugin” functionality

• …

Page 9: Intro to Ushahidi for Developers

Query

Processing

Output

Output

Query

Output

Processing

Final OutputView

Flow: Traditional vs. MVC

ModelController

Page 10: Intro to Ushahidi for Developers

Kohana

• Kohana (http://kohanaframework.org/) is a PHP5 framework that uses the Model View Controller architectural pattern. It aims to be secure, lightweight, and easy to use.

• Documentation: http://docs.kohanaphp.com/ • http://learn.kohanaphp.com/ 

Page 11: Intro to Ushahidi for Developers
Page 12: Intro to Ushahidi for Developers
Page 13: Intro to Ushahidi for Developers
Page 14: Intro to Ushahidi for Developers

class Country_Model extends ORM{protected $belongs_to = array('location');protected $has_many = array('city');

// Database table nameprotected $table_name = 'country';}

Example Model: Country

Page 15: Intro to Ushahidi for Developers

<div id="content"><div class="content-bg"><!-- start search block --><div class="big-block"><h1>Search Results</h1><div class="search_block"><?php echo $search_info; ?><?php echo $search_results; ?></div></div><!-- end search block --></div></div></div></div></div>

Example View: Search Results

Page 16: Intro to Ushahidi for Developers

Example Controller: Error class Error_Controller extends Controller{/** * Render Custom 404 Error Page */public function error_404(){Header("HTTP/1.0 404 Not Found");

$this->layout = new View('error');$this->layout->title = Kohana::lang('ui_admin.page_not_found');$this->layout->content = Kohana::lang('ui_admin.page_not_found_message');$this->layout->render(true);}}

Page 17: Intro to Ushahidi for Developers

Working with GIT

• GIT is a version control system much like SVN• The concepts are more or less the same - revisions, commits… 

• Ushahidi hosts source code repositories with GitHub - 

• http://github.com/ushahidi• http://github.com/ushahidi/Ushahidi_Web

Page 18: Intro to Ushahidi for Developers

Basic commands

Page 19: Intro to Ushahidi for Developers

Learning Links

• GitHub Guide - http://github.com/guides• Git Home - http://git.or.cz/• http://github.com/guides/git-cheat-sheet• Git - SVN Crash Course - http://git.or.cz/course/svn.html

• O'Reilly Webcast: Git in One Hour - http://www.youtube.com/watch?v=OFkgSjRnay4

Page 20: Intro to Ushahidi for Developers

More

• Developer guide: http://wiki.ushahidi.com/doku.php?id=developer