4

How can I access the getid3 class and use it in my controller?

project
 /application
 /controller
 /libraries
    /getID3
       /getid3
          getid3.php
 /model
 /views   
Owen Bula
  • 89
  • 1
  • 3
  • 11

4 Answers4

2

Use CodeIgniter's built in constant, APPPATH. (Because code is not written in codeigniter's syntaxes)

`require_once(APPPATH.'libraries/getID3/getid3/getid3.php');`

If this library is codeigniter's built in library then you should use.

$this->load->library('libary name');
Bhavin
  • 2,070
  • 6
  • 35
  • 54
2

Regarding Your File Structure Codeigniter has the solution for it:

project
/application
/controller
/libraries
    /getID3
        /getid3
            getid3.php
/model
/views 

Now To call the Getid3.php the library you need to add this below code in the controller.

$this->load->library ( 'getID3/getid3/getid3', '', 'getid3(you can add any name you want' );

Now to Use this:

$this->getid3->your_function($data);

Please Note that Getid3.php must start with the capital letter.

always-a-learner
  • 3,671
  • 10
  • 41
  • 81
0

From CI Documentation

you can load library by doing

$this->load->library('getID3/getid3/Getid3');

As explained in documentation if you have file located in a subdirectory like
libraries/flavors/Chocolate.php
You will load it using:

$this->load->library('flavors/chocolate');

Regolith
  • 2,944
  • 9
  • 33
  • 50
  • your file name should be like this `Getid3.php`. see [File Naming](https://www.codeigniter.com/user_guide/general/styleguide.html#file-naming) – Regolith Jul 10 '17 at 10:49
0

You COULD just do a require_once on the main GetID3.php file

require_once(APPPATH.'libraries/getID3/getid3/getid3.php');

but there are better, more cleaner ways, to manage this third party dependency.

Instead of directly requiring the GetID3.php file, I recommend creating a wrapper class for the library. Creating a wrapper class affords you the ability to extend/overwrite the getid3 library and provides a cleaner implementation by allowing you to do things the "codeigniter way".

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

class GetID3 {  

    function __construct ( $options = array() )
    {
        require_once( APPPATH . 'third_party/getID3/getid3/getid3.php' );
    }

    public function __get( $var ) { return get_instance()->$var; }
}

Doing it this way provides a cleaner interface to work with and allows for a more scalable approach to managing the third party dependency. Also, not the directory structure. Here, we are saving third party dependencies to the third_party directory while saving the wrapper class to libraries/GetID3.php.

Once you've implemented it this way, you can load the library as you normally would:

$this->load->library('GetID3');
KFE
  • 637
  • 5
  • 10