CodeIgniter For Project : Lesson 106 - Model

Preview:

Citation preview

CodeIgniter For ProjectLesson 106 : Model

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

https://kusumotolab.com

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.

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

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

• 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

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

https://kusumotolab.com

Model

ModelLoad default database configuration

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

https://kusumotolab.com

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

• Select

• Insert

• Update

• Delete

Query Builder / Active Record

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

https://kusumotolab.com

Select

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

https://kusumotolab.com

Select

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

https://kusumotolab.com

Insert

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

https://kusumotolab.com

Update

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

https://kusumotolab.com

Delete

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

https://kusumotolab.com

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

Link Model to Controller and show result on View

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

https://kusumotolab.com

Link Model to Controller and show result on View

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

https://kusumotolab.com

Link Model to Controller and show result on View

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

https://kusumotolab.com

Link Model to Controller and show result on View

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

https://kusumotolab.com

Forward to Workshop 005

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

https://kusumotolab.com