4

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

project
 /application
 /controller
 /libraries
    /getID3
       /getid3
          getid3.php
 /model
 /views   
7
  • check this Commented Jul 10, 2017 at 10:30
  • getid3.php's code is written in codeigniter syntaxes? or it's totally diffrent ? Commented Jul 10, 2017 at 10:32
  • @Bhavin it's a different code. An external library. Commented Jul 10, 2017 at 10:33
  • @Regolith 'Unable to load the requested class: Getid3' Commented Jul 10, 2017 at 10:38
  • @OwenBula. Ok see my answer. Commented Jul 10, 2017 at 10:38

4 Answers 4

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');
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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');

1 Comment

your file name should be like this Getid3.php. see File Naming
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');

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.