How to Create Custom Library into CodeIgniter? - PowerPoint PPT Presentation

About This Presentation
Title:

How to Create Custom Library into CodeIgniter?

Description:

Codeigniter library means class file located into the classes “application/libraries” directory. You might have to remember a few things when creating a custom library in CI. It is a very simple process. Download the third party library and put it inside your library or third party folder and you can load this in the same way as you load your other libraries.Checkout the following method: – PowerPoint PPT presentation

Number of Views:4
Slides: 9
Provided by: gracemiller7
Category: Other
Tags:

less

Transcript and Presenter's Notes

Title: How to Create Custom Library into CodeIgniter?


1
(No Transcript)
2
How to Create Custom Library into CodeIgniter?
  • Elsner Technologies

3
How to Create Custom Library into CodeIgniter?
  • Nowadays, there are many readymade classes
    available for the payment gateway, pdf
    generation, some third party API. So lets see
    how to integrate these classes to codeigniter and
    use it like a library. We can create our own
    class and use it as library.
  • Codeigniter library means class file located into
    the classes application/libraries directory.
    You might have to remember a few things when
    creating a custom library in CI.
  • It is a very simple process. Download the third
    party library and put it inside your library or
    third party folder and you can load this in the
    same way as you load your other libraries.

4
Checkout the following method
  • 1. Filename of class and class name must be
    matching otherwise when you load the library, it
    will generate fatal error.
  • Ex. Filename will be Paypal.php so class would
    be like this
  • lt?php
  • if ( ! defined(BASEPATH)) exit(No direct
    script access allowed)
  • class Paypal
  • public function sendpayment()
  • // do your stuff
  • ?gt

5
  • 2. You can load this library into controller,
    model or view.
  • Ex. this-gtload-gtlibrary(paypal)
  • 3. To use default codeignitor functionality like
    built in libraries, you have to get instance of
    CI and then use all database and other
    functionalities.
  • Ex.
  • function Authex()
  • CI get_instance()
  • //load libraries
  • CI-gtload-gtdatabase()
  • CI-gtload-gtlibrary(session)

6
  • 4. To pass the parameter to constructor or
    intialization with class we can pass with load
    libarary.
  • Ex.
  • arrTemp array(authkeygtXXXX)
  • this-gtload-gtlibrary(Paypal, arrTemp)
  • class Paypal
  • public function __construct(arr)
  • // put your functionality here.

7
  • 5. To extend the native libraries, some things
    regarding the syntax and parent class extendsion
    are very useful which are mentioned here. You can
    replace native libraries.
  • library name must be start with MY_
  • Class must extend parent class
  • Add subclass_prefix to config file
  • Ex. configsubclass_prefix MY_
  • If you want to check the all the user logins, go
    through our custom controller first and then
    particular controller so we can extend
    CI_controller like mentioned in the below sample
    class.
  • class MY_Controller extends CI_Controller
  • function __construct(data)
  • parent__construct()
  • this-gtdata array()
  • user this-gtsession-gtuserdata(current_user)
  • if (!user)
  • redirect(login)
  • else

8
Contact us
  • Media Contact
  • Company name Elsner Technologies Pvt. Ltd
  • Website https//www.elsner.com/
  • Email sales_at_elsner.com
  • Facebook https//www.facebook.com/ElsnerTechnolo
    giesPvtLtd
  • Twitter https//twitter.com/Elsnertech
Write a Comment
User Comments (0)
About PowerShow.com