Vous êtes sur la page 1sur 30

Developing

Economic Intelligence Application


with

and
Outlines
• About Economic Intelligence Application
– Overview
• Introduction to Kohana
– Why Kohana?
• Features in Kohana PHP
– Drivers, Helpers, Libraries
– Controller, Model (ORM), View
• jQuery implementation
• Sample codes
Intelligence Cycle

1
2
Planning
Collection
& Direction

3 3 Processing

5 Processing
Dissemination

4 Analysis

Analysis
Modules in EIDA
VISION
MISSION
OBJECTIVES
STRATEGIES
DASHBOARD
1. PERSONAL 2. E-MAIL 3. DATASET

4. CHARTS 5. TABLES 6. MAPPING 7. QUERY 8. DOCUMENT 9. NEWS

ANALYSIS
10. REPORTING 11. MOLAP 12. WORKSHEET

MULTI-DIMENSION DATASET
13. TIME 14. ENTITY 15. PROJECT 16. ITEM 17. GEOGRAPHY 18. MEASURE

19. DATA 20. FILE 21. FILE 22. DATA 23. RSS 24. HTML
ENTRY UPLOAD IMPORT LOAD AGGREGATE SELECT

ACCESS CONTROL
25. USER MANAGER 26. DATASET MANAGER 27. LOG STATISTICS
Modules
• Developed with
– Kohana PHP – Web app framework
– jQuery – JavaScript framework
What is Kohana PHP ?
• A web application framework
• Designed for PHP 5.2
• Fully Object Oriented Programming approach
• Uses MVC – Model View Controller
architecture pattern

Kohana PHP
THE SWIFT PHP5 FRAMEWORK
Why Kohana PHP ?
• Full support PHP 5.2 OOP API
– interfaces, abstracts, singletons, public, private, protected and
automatic class loading.
– All PHP5 magics available _get() _set() _destruct() etc…
• Strict OOP & MVC coding as RAD tool
– More logical structure to apps
• Cascading file system
– Allow Plug & Play MVC modules
– Never touch the core.
• Built in ORM – Object Relational Model
– Say goodbye to SQL strings !
– Built with performance in minds.
• Secured
– SQL execution escaped (prevent injection)
– GET, POST, COOKIE cleaned automagically. (prevent XSS)
Driver… what is drivers?
• Kohana Driver: – Cache Drivers:
– Collection of standard API • Use cache engine which
available on your server
with different backend – APC, eAccelerator, Memcache,
– Uses abstract class as SQLite, Xcache, flat file
definition & implements – Image Drivers:
• Module generating graphics
portability enhanced by
• Drivers Collection in Kohana – GD, ImageMagick,
GraphicMagick
– Database Drivers:
– Captcha Drivers:
• Query Builder / ORM may
connect to these database • Choose your captcha strategy
preference
– MySQL/i, SQLite, Postgres,
– Alpha, Black, Basic, Math,
MsSQL Riddle, Word …
– Session Drivers: – Payment Drivers
• Session Driver handle • Payments API support
session storage – Authorize, PayPal, Paypal Pro,
– Database, Cookie or in Cache Google Checkout, Trident,
Engine Trust Commerce, YourPay.
ORM Library
• ORM definition (in simple word)
– Object Relational Mapping
– PHP object property (class attr.) mapped to a table and fields
• API for create, read, update & delete
– Attributes value in the object loaded automatically from database
upon object construct
– Values assigned to the object attributes can be saved easily
– No SQL string. No writing joins. QueryBuilder do SQL queries silently.
• Support table relationship (for normalized data)
– $has_one for one-to-one relationships
– $has_many for the parent side of a one-to-many relationship
– $belongs_to for the child side of a one-to-many relationship
– $has_and_belongs_to_many for many-to-many relationships
• Speed up CRUD developments.
Example of Using ORM
$user = ORM::factory(‘user’);
// creating an object

$user->name = ‘Sanda’;
$user->password = ‘paS$w0rD’;
$user->email = ‘fasha@mail.com’;
// assigning new values

$user->save(); // without INSERT INTO

//Get full src. at:


http://software.krimnet.com/kohana
Cascading File System
• Enables plug-and-
play modules in MVC
environment.
All files merged in a
folder at run-time
jQuery implementation with Kohana
• No specific JavaScript framework
implementation in Kohana
• Contributed module/helper projects
– manage JavaScript globally & cache.
– JS/CSS Collector, Assets, Minify OR Media
module
– Keep JS/CSS files inside modules folder
Tips Handling JavaScript
• How to Keep MVC approach
– Separate static JavaScript with dynamic JavaScript
– Treat JavaScript as View.
– Put dynamic JavaScript in View object.
• Advantages
– Utilize JS collector
– Minify object output on the fly
Inside View Template
File:veiws/grid_script.php
<script>
jQuery("#list2").jqGrid({
url:'<?=$url?>',
datatype: "json",
colNames: <?=$column_name?>,
colModel: <?=$column_model?>,
rowNum: <?=$row_num?>,
rowList: <?=$row_list?>,

pager: jQuery('#pager2'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption: "<?=$caption?>"
}).navGrid('#pager2',{edit:false,add:false,del:false});
</script>
Pass dynamic vars. to View
$script = View::factory('grid_script')
->set('caption', $caption)
->set('url', $url)
->set('column_name', $column_name)
->set('column_model', $column_model)
->set('row_num', $row_num)
->set('row_list', $row_list);
Layout View
<html>
<head>
<title>Title</title>
<link href="/kohana/assets/jqgrid/css/ui.jqgrid.css" media="all"
rel="stylesheet" type="text/css" />
<link href="/kohana/assets/jqgrid/css/redmond/jquery-ui-1.7.1.custom.css"
media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<table id="list2" class="scroll"></table>
<div id="pager2" class="scroll" style="text-align:center;"></div>

<script src="/kohana/assets/jqgrid/js/jquery-1.3.2.min.js"></script>
<script src="/kohana/assets/jqgrid/js/jquery-ui-1.7.1.custom.min.js">
</script>
<script src="/kohana/assets/jqgrid/js/i18n/grid.locale-en.js"></script>
<script src="/kohana/assets/jqgrid/js/jquery.jqGrid.js"></script>

<?=$script ?> //equals to echo $script


</body>
</html>
Q&A
• Website: kohanaphp.com
• Documentation: docs.kohanaphp.com
• Community: forum.kohanaphp.com

• Blog: http://software.krimnet.com/kohana
Extras
Kohana Controller
• URL: http://myapp.com/module/function/para1/para2/ … /
• The URL mapped into controller file below
• This file located at: /app_folder/modules/user/controllers/user.php

User_Controller extends Controller


{
public function edit($para1, $para2, ...)
{
// your code here
echo ‘<html>
<body>Output to browser</body>
</html>’;
}
}
Kohana Model (with ORM)
Eg: Table Users
id name password email

User_Model extends ORM


{
protected $table_name = ‘users’;
}

• User model located at /app_path/modules/user/models/user.php


• Other optional properties available:
– $primary_key, $primary_val, $table_columns, $has_one, $has_many, ... (see
documentation for more …)
ORM (Example – Load a table row)
id name password email

2 Fasha ***** fasha@xmail.com

http://myapps/user/view/2

User_Controller extends Controller


{
public function view($id)
{
$user = ORM::factory(‘user’, $id);
// load row id=2 into $user without SELECT * FROM … WHERE …

$pass = $user->password; // copying a field value


echo $user->name; // echo a field value, output: Fasha
echo $user->email; // echo a field value, output: fasha@xmail.com
}
}
ORM (Example – Edit a table row)
id name password email

2 Sanda xxxxx sanda@mail.com

2 Fasha ***** fasha@xmail.com

http://myapps/user/edit/2

User_Controller extends Controller


{
public function edit($id)
{
$user = ORM::factory(‘user’, $id);
// load row id=2 without SELECT * FROM ...
$user->name = ‘Fasha’; // assigning new value
$user->password = ‘paS$w0rD’;
$user->email = ‘fasha@xmail.com’;
$user->save(); // skip UPDATE … TABLE … WHERE id=2
}
}
View Example
• http://myapps/user/show/2 • /modules/user/views/
• /modules/user/controllers/user.php user_view.php

User_Controller
<html>
extends Controller {
<body>
<div id=“user”>
public function show($id) {
<p>Name: <?=$name?>
$user =
</p>
ORM::factory(‘user’, $id);
<p>Email: <?=$email?>
</p>
echo
View::factory(‘user_view’) </div>
</body>
->set(‘name’, $user->name)
->set(‘email’, $user->email);
</html>
}
}
www.transformersgame.com
www.mypicsmap.com
tutlist.com
Why Kohana PHP ?
• Community support
– Official Forum: Active (1500 members)
– Central Projects Repository: Active (40 projects)
– Official Documentation: Sufficient
• Official & contributed extendable drivers
– Database, Cache, Auth, Session, Captcha, Image, Form
Element …etc
• Ready for production
– Current release v2.3.2 (svn/trunk has the latest)
– Ver 2.4 (on-going) … Ver 3.0 (in planning)

Vous aimerez peut-être aussi