Codeigniter

Codeigniter Model

Models deals with back end operations .Fetch data from database and send to controller. All database related manipulation is done by CI Model.

For ex –  Select, Fetching records, update and delete.

Location of  all model files is applications/models and CI model are control and accessed by controller.

How to use CI Models

  • Load database library
  • Define database configuration  in database.php file
  • Create Model
  • How to load model in Controller

Load database library

You have to define above library in every model if you want to reduce the lines of code then you can define database library in autoload.php file. Open application/config/autoload.php and add the database library in library array().

How to Define database connection

Open applications/config/database.php and define database configuration.

How to create CI Model

  • Model Class will be created inside the application/model folder.
  • You can also create a new folder inside application/model and save your files in this folder.
  • Model class will be inherit  from its base class CI_Model.
  • Use active record database pattern.
How to load model in controller

About the author

Anuj kumar

I'm Anuj kumar a web developer with 4+ year experience .I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to is provide php , jquery , mysql , phpoops and other web development tutorials. I am trying best effort to make PHPGurukul useful for every single moment spend on this website. If you think this website is useful to visit please share with your friend and buddies.

Leave a Comment

Subscribe For Latest Updates