Welcome Guest, Not a member yet? Register   Sign In
How to use external php library in codeigniter?
#2

The problem is that CI can find the 'caxy/htmldiff/htmldiff' file, but cannot find any of the files it needs to load.

My suggestion is to install caxy/php-htmldiff using Composer as described on their Readme page.

Then in the file /application/config.config.php use the following setting in the Composer auto-loading section

PHP Code:
$config['composer_autoload'] = FCPATH.'vendor/autoload.php'

In the controller that will load and use htmldiff put the following immediately after the opening PHP tag, e.g.

PHP Code:
<?php
use Caxy\HtmlDiff\HtmlDiff

Do not use
PHP Code:
$autoload['libraries'] = array( 'caxy/htmldiff/htmldiff'); 

You should not use $this->load->library(). either. Instead, when you want to instantiate HtmlDiff use "new". Below I create a class property to hold the HtmlDiff object when you create one. In this example I do so in the compare method


PHP Code:
<?php
use Caxy\HtmlDiff\HtmlDiff;

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

class 
Files extends CI_Controller
{
    protected $htmldiff;

    public function compare($oldHtml$newHtml)
    {
        $this->htmldiff = new HtmlDiff($oldHtml$newHtml);
        //do your thing
    }



If you want to use a HtmlDiffConfig Object include the following line right after the first "use: statement

PHP Code:
use Caxy\HtmlDiff\HtmlDiffConfig
Reply


Messages In This Thread
RE: How to use external php library in codeigniter? - by dave friend - 09-08-2019, 02:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB