Where a newly created library is stored in CodeIgniter structure?

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPin on PinterestPrint this pageEmail this to someone

What is a Php CodeIgniter Library
CodeIgniter provide a rich set of libraries. It is an essential part of CodeIgniter as it increases the developing speed of an application. It is located in the system/library.
Loading CodeIgniter Library
CodeIgniter library can be loaded as following,

1
$this->load->library('class_name');

Here, class name should be replaced by the name of the library.
To load multiple libraries, use following code,

1
$this->load->library(array('email', 'table'));

Creating CodeIgniter Libraries
All the CodeIgniter libraries are set in framework organizer. Be that as it may, on the off chance that in the event that you need to utilize some other library in your application you can make it. There is no confinement for libraries. Be that as it may, your made libraries will be put away in the application/libraries envelope. This is done to isolate your neighborhood and worldwide system assets.
There are three methods to create a library,

  • Creating an entire new library
  • Extending native libraries
  • Replacing native libraries

Creating an entire new library
It should be placed in application/libraries folder.
Naming Conventions

  • File name first letter has to be in uppercase letter, like Queryanswer.php
  • Class name first letter should also be in uppercase letter
  • File name and class name should be same.

Basic syntax:
Suppose your file name is Queryanswer.php, then syntax will be as follows,
Loading Queryanswer.php
It can be loaded with the following line,

1
$this->load->library('Queryanswer.php');

Note: You can write library name in any one of the upper or lower case letter.
Accessing Queryanswer.php
Once it is loaded, you can access your class using the lower case letter because object instances are always in lower case.

Extending Native Libraries
You can also add some extended functionality to a native library by adding one or two methods. It will replace the entire library with your version. So it is better to extend the class. Extending and replacing is almost identical with only following exceptions.

Leave a Reply

Your email address will not be published. Required fields are marked *