codeigniter for project : lesson 106 - model

20
CodeIgniter For Project Lesson 106 : Model Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd https://kusumotolab.com

Upload: weerayut-hongsa

Post on 18-Jan-2017

318 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: CodeIgniter For Project : Lesson 106 - Model

CodeIgniter For ProjectLesson 106 : Model

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 2: CodeIgniter For Project : Lesson 106 - Model

Model

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your

database.

Page 3: CodeIgniter For Project : Lesson 106 - Model

CodeIgniter Database Support • MySQL (4.1+)

• MySQLi

• MS SQL

• Postgres

• Oracle

• SQLite

• ODBCWeerayut Hongsa : Network Engineer / Software Developer

Major Kantana Broadcasting Co., Ltd https://kusumotolab.com

Page 4: CodeIgniter For Project : Lesson 106 - Model

Caution : Security!To Create files associated with CodeIgniter must add code to check BASEPATH.

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 5: CodeIgniter For Project : Lesson 106 - Model

• Model file store in /application/models

• Model Name matched Filename.

• First character in Model Name is upper case only.

• You CodeIgniter Model must always extends CI_Model class.

• in __construct method, you need to load database driver.

Model

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 6: CodeIgniter For Project : Lesson 106 - Model

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Model

Page 7: CodeIgniter For Project : Lesson 106 - Model

ModelLoad default database configuration

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 8: CodeIgniter For Project : Lesson 106 - Model

Query Builder / Active Record

CodeIgniter gives you access to a Query Builder class. This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. In some cases only one or two lines of code are necessary to perform a

database action. CodeIgniter does not require that each database table be its own class file. It instead provides a more simplified interface.

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 9: CodeIgniter For Project : Lesson 106 - Model

• Select

• Insert

• Update

• Delete

Query Builder / Active Record

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 10: CodeIgniter For Project : Lesson 106 - Model

Select

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 11: CodeIgniter For Project : Lesson 106 - Model

Select

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 12: CodeIgniter For Project : Lesson 106 - Model

Insert

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 13: CodeIgniter For Project : Lesson 106 - Model

Update

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 14: CodeIgniter For Project : Lesson 106 - Model

Delete

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 15: CodeIgniter For Project : Lesson 106 - Model

Link Model to Controller and show result on View

• Load model to your controller.

• Assign data from model function to variable in controller.

• Send variable to View.

• Loop get data from variable to show in View.

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 16: CodeIgniter For Project : Lesson 106 - Model

Link Model to Controller and show result on View

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 17: CodeIgniter For Project : Lesson 106 - Model

Link Model to Controller and show result on View

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 18: CodeIgniter For Project : Lesson 106 - Model

Link Model to Controller and show result on View

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 19: CodeIgniter For Project : Lesson 106 - Model

Link Model to Controller and show result on View

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com

Page 20: CodeIgniter For Project : Lesson 106 - Model

Forward to Workshop 005

Weerayut Hongsa : Network Engineer / Software Developer Major Kantana Broadcasting Co., Ltd

https://kusumotolab.com