41
Web Application Development using MVC Framework Kohana Arafat Rahman Web Application Developer Solution Arena http://arafatbd.net

Web Application Development using MVC Framework Kohana

Embed Size (px)

Citation preview

Page 1: Web Application Development using MVC Framework Kohana

Web Application Development using MVC Framework Kohana

Arafat RahmanWeb Application Developer

Solution Arenahttp://arafatbd.net

Page 2: Web Application Development using MVC Framework Kohana

Framework ?

Provides Generic

functionality Some key features Reusable Well-defined Specialized by user

Page 3: Web Application Development using MVC Framework Kohana

Why Kohana (KO3) Its MVC Its HMVC Very fast framework Strict PHP 5.2 - OOP and extremely DRY Many common components Simple routing structure

Page 4: Web Application Development using MVC Framework Kohana

MVC ?

Model-View-Controller

Page 5: Web Application Development using MVC Framework Kohana

MVC

Page 6: Web Application Development using MVC Framework Kohana

HMVC ?

Hierarchical Model View Controller

Page 7: Web Application Development using MVC Framework Kohana

MVC and HMVC

Page 8: Web Application Development using MVC Framework Kohana

Setting up Kohana (KO3)

Page 9: Web Application Development using MVC Framework Kohana

Setting up Kohana

Page 10: Web Application Development using MVC Framework Kohana

Configuration

application/bootstrap.php

Kohana::init(array('base_url' => '/kohana/',));

Page 11: Web Application Development using MVC Framework Kohana

Configuration (cont.)

Delete /install.php

Page 12: Web Application Development using MVC Framework Kohana

Requesting a Controller

/index.php/<controller>/<action>

example:/index.php/topic/view/123

Page 13: Web Application Development using MVC Framework Kohana

Hello, world!

Page 14: Web Application Development using MVC Framework Kohana

Hello, world! (cont.)

http://localhost/kohana/index.php/welcome

Page 15: Web Application Development using MVC Framework Kohana

Hide index.php

How to hide index.php

http://kerkness.ca/wiki/doku.php?id=removing_the_index.php

Page 16: Web Application Development using MVC Framework Kohana

Hello, world! (cont.)

http://localhost/kohana/welcome

Page 17: Web Application Development using MVC Framework Kohana

Database Configapplication/bootstrap.php

Page 18: Web Application Development using MVC Framework Kohana

Database Config (cont.)application/config/database.php

Page 19: Web Application Development using MVC Framework Kohana

Database Config (cont.)application/config/database.php

Page 20: Web Application Development using MVC Framework Kohana

Create Table: topicsCREATE 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) ;

Page 21: Web Application Development using MVC Framework Kohana

Reading Database Recordsapplication/classes/controller/topic.php

Page 22: Web Application Development using MVC Framework Kohana

Reading Database Recordsapplication/classes/controller/topic.phptry {

$data['topics'] = DB::select()

->from('topics')

->order_by('date', "DESC")

->execute()

->as_array();

$this->request->response = View::factory('list', $data);

}

Page 23: Web Application Development using MVC Framework Kohana

Reading Database Recordsapplication/view/list.php

Page 24: Web Application Development using MVC Framework Kohana

Reading Database Recordsapplication/view/list.php

Page 25: Web Application Development using MVC Framework Kohana

Reading Database Recordsapplication/view/list.php

Page 26: Web Application Development using MVC Framework Kohana

Inserting New Recordsapplication/classes/controller/topic.php

http://localhost/kohana/topic/new_topic

Page 27: Web Application Development using MVC Framework Kohana

Inserting New Records (cont.)http://localhost/kohana/topic/new_topic

Page 28: Web Application Development using MVC Framework Kohana

Inserting New Records (cont.)application/classes/controller/topic.php

Page 29: Web Application Development using MVC Framework Kohana

Inserting New Records (cont.)application/classes/controller/topic.php

Page 30: Web Application Development using MVC Framework Kohana

Inserting New Records (cont.)application/classes/controller/topic.php

Page 31: Web Application Development using MVC Framework Kohana

Update Recordshttp://localhost/kohana/topic/index

Page 32: Web Application Development using MVC Framework Kohana

Update Records (cont.)application/classes/controller/topic.php

Page 33: Web Application Development using MVC Framework Kohana

Update Records (cont.)application/classes/controller/topic.php

Page 34: Web Application Development using MVC Framework Kohana

Update Records (cont.)http://localhost/kohana/topic/edit/1

Page 35: Web Application Development using MVC Framework Kohana

Update Records (cont.)application/classes/controller/topic.php

Page 36: Web Application Development using MVC Framework Kohana

Update Records (cont.)application/classes/controller/topic.php

Page 37: Web Application Development using MVC Framework Kohana

Model and ORMObject Relational Mapping (ORM)

application/classes/model/topic.php

class Model_Topic extends ORM { ...}

Page 38: Web Application Development using MVC Framework Kohana

HMVCIn a View<?php echo $content;?><br/><?php echo Request::factory('topic/featured')

->execute()->response;?>

Page 39: Web Application Development using MVC Framework Kohana

HMVC (cont.)In a Controller$data['featured'] = Request::factory('topic/featured')

->execute()->response;

Page 40: Web Application Development using MVC Framework Kohana

References Kohana Documentation

http://kohanaframework.org/documentation Unofficial documentaion

http://kerkness.ca/wiki/doku.php

Page 41: Web Application Development using MVC Framework Kohana

Questions ?Again, I am

Arafat Rahmanhttp://arafatbd.net