1

I would like to use http://demo.hazzardweb.net/imgPicker/docs/. I have downloaded all the files.

How can I convert it into a Codeigniter third party library or how can I call this class file in a Codeigniter controller? Is it possible to call the core php files directly in a controller to achieve this?

For example:

 require dirname(__FILE__) . '/ImgPicker.php';

1 Answer 1

2

You can create a new library for your project.

Your library classes should be placed within your application/libraries directory, as this is where CodeIgniter will look for them when they are initialized.

Be sure that:

  • File names must be capitalized. For example: ImgPicker.php
  • Class declarations must be capitalized. For example: class ImgPicker
  • Class names and file names must match.

Your ImgPicker class file Classes in general should have this basic prototype:

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class ImgPicker {

        // all stuff that your php library does
        public function some_method()
        {
            . . . 
        }
}

Then from your controller (or model) you can load your library with $this->load->library('someclass'); and you can pass vars to the constructor dynamically like so:

$params = array('type' => 'large', 'color' => 'red');
$this->load->library('ImgPicker', $params);

You can find a lot of useful information how to create your own libraries (or convert existing php classes to CI libraries) at CI documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.