Ushahidi 101
•Setting up a development environment•Introduction to MVC and the Kohana (PHP) framework•Working with GIT
Setting up: Prerequisites
• MySQL• PHP 5• Apache
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
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.
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)
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.
Why use an MVC framework?
• Avoid “reinventing the wheel”
• Use proven, tested code
• Automation (ORM, generators)
• Maintainability
• “Plugin” functionality
• …
Query
Processing
Output
Output
Query
Output
Processing
Final OutputView
Flow: Traditional vs. MVC
ModelController
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/
class Country_Model extends ORM{protected $belongs_to = array('location');protected $has_many = array('city');
// Database table nameprotected $table_name = 'country';}
Example Model: Country
<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
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);}}
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
Basic commands
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
More
• Developer guide: http://wiki.ushahidi.com/doku.php?id=developer
Top Related