The Basques conceived in Libraries were a way of extending Codeigniter functions through classes.
If you compare the empty anatomy of the Library and the Model in Codeigniter, you will see that Models extend CI_MODEL , which allows you to access your own Codeigniter resources (for example $ this-> db).
Libraries do not offer this basic access, and they also do not need to be expanded through CI_MODEL .
Models are created for displaying and interacting with data (mainly abstracted from databases such as mysql).
Take a look at the main library
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Library{ public function MyFunction(){
... and Model Anatomy
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class User_model extends CI_Model { public function __construct(){ parent::__construct(); } public function MyFunction(){
In most cases, Models are ready to use Ressources to access databases or other functions. There is no library. You need to enable or extend Ressources manually if you need it:
//Create an CI instance $CI =& get_instance();
Libraries are collections of tools and feature extensions, and Models are ideal for abstracting and interacting with data coming from databases.
Mike
source share