Web Application Development
using MVC Framework Kohana
Arafat Rahman
Web Application Developer
Solution Arena
http://arafatbd.net
Framework ?
Provides

Generic
functionality

Some key features

Reusable

Well-defined

Specialized by user
Why Kohana (KO3)

Its MVC

Its HMVC

Very fast framework

Strict PHP 5.2 - OOP and extremely DRY

Many common components

Simple routing structure
MVC ?
Model-View-Controller
MVC
HMVC ?
Hierarchical Model View Controller
MVC and HMVC
Setting up Kohana (KO3)
Setting up Kohana
Configuration
application/bootstrap.php
Kohana::init(array(
'base_url' => '/kohana/',
));
Configuration (cont.)
Delete

/install.php
Requesting a Controller
/index.php/<controller>/<action>
example:
/index.php/topic/view/123
Hello, world!
Hello, world! (cont.)
http://localhost/kohana/index.php/welcome
Hide index.php
How to hide index.php
http://kerkness.ca/wiki/doku.php?
id=removing_the_index.php
Hello, world! (cont.)
http://localhost/kohana/welcome
Database Config
application/bootstrap.php
Database Config (cont.)
application/config/database.php
Database Config (cont.)
application/config/database.php
Create Table: topics
CREATE TABLE `kohana`.`topics` (
`topic_id` INT( 11 ) NOT NULL
AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 250 ) NOT
NULL ,
`description` TEXT NOT NULL ,
`date` DATETIME NOT NULL
) ;
Reading Database Records
application/classes/controller/topic.php
Reading Database Records
application/classes/controller/topic.php
try {
$data['topics'] = DB::select()
->from('topics')
->order_by('date', "DESC")
->execute()
->as_array();
$this->request->response =
View::factory('list', $data);
}
Reading Database Records
application/view/list.php
Reading Database Records
application/view/list.php
Reading Database Records
application/view/list.php
Inserting New Records
application/classes/controller/topic.php
http://localhost/kohana/topic/new_topic
Inserting New Records (cont.)
http://localhost/kohana/topic/new_topic
Inserting New Records (cont.)
application/classes/controller/topic.php
Inserting New Records (cont.)
application/classes/controller/topic.php
Inserting New Records (cont.)
application/classes/controller/topic.php
Update Records
http://localhost/kohana/topic/index
Update Records (cont.)
application/classes/controller/topic.php
Update Records (cont.)
application/classes/controller/topic.php
Update Records (cont.)
http://localhost/kohana/topic/edit/1
Update Records (cont.)
application/classes/controller/topic.php
Update Records (cont.)
application/classes/controller/topic.php
Model and ORM
Object Relational Mapping (ORM)
application/classes/model/topic.php
class Model_Topic extends ORM {
...
}
HMVC
In a View
<?php echo $content;?><br/>
<?php echo
Request::factory('topic/featured')
->execute()->response;
?>
HMVC (cont.)
In a Controller
$data['featured'] =
Request::factory('topic/featured')
->execute()->response;
References

Kohana Documentation
http://kohanaframework.org/documentation

Unofficial documentaion
http://kerkness.ca/wiki/doku.php
Questions ?
Again, I am
Arafat Rahman
http://arafatbd.net

Web Application Development using MVC Framework Kohana