পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Tuesday, February 14, 2017

CodeIgniter - Libraries

The essential part of a CodeIgniter framework is its libraries. It provides a rich set of libraries, which indirectly increase the speed of developing an application. The system library is located at system/libraries. All we need to do is to load the library that we want to use. The library can be loaded as shown below −
$this->load->library('class name');
Where class name is the name of the library that we want to load. If we want to load multiple libraries, then we can simply pass an array as argument to library() function as shown below −
$this->load->library(array('email', 'table'));

Library Classes

The library classes are located in system/libraries. Each class has various functions to simplify the developing work. Following table shows the names of the library class and its description.

Creating Libraries

CodeIgniter has rich set of libraries, which you can find in system/libraries folder but CodeIgniter is not just limited to system libraries, you can create your own libraries too, which can be stored in application/libraries folder. You can create libraries in three ways.
  • Create new library
  • Extend the native library
  • Replace the native library

Create New Library

While creating new library one should keep in mind, the following things −
  • The name of the file must start with a capital letter e.g. Mylibrary.php
  • The class name must start with a capital letter e.g. class Mylibrary
  • The name of the class and name of the file must match.
Mylibrary.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
   
   class Mylibrary {
 
      public function some_function() {
      }
   }
 
/* End of file Mylibrary.php */
Loading the Custom Library
The above library can be loaded by simply executing the following line in your controller.
$this->load->library(‘mylibrary’);
mylibrary is the name of your library and you can write it in lowercase as well as uppercase letters. Use the name of the library without “.php” extension. After loading the library, you can also call the function of that class as shown below.
$this->mylibrary->some_function();

Extend the Native Library

Sometimes, you may need to add your own functionality to the library provided by CodeIgniter. CodeIgniter provides facility by which you can extend the native library and add your own functions. To achieve this, you must extend the class of native library class. For example if you want to extend the Email library then it can be done as shown below −
Class MY_Email extends CI_Email { 
}
Here, in the above example, MY_Email class is extending the native library’s email class CI_Email. This library can be loaded by the standard way of loading email library. Save the above code in file My_Email.php

Replace the Native Library

In some situations, you do not want to use the native library the way it works and want to replace it with your own way. This can be done by replacing the native library. To achieve this, you just need to give the same class name as it is named in native library. For example, if you want to replace the Email class, then use the code as shown below. Save your file name with Email.php and give a class name to CI_Email.
Email.php
Class CI_Email { 
}

No comments:

Post a Comment