Welcome Guest, Not a member yet? Register   Sign In
Convert this PHP Class to CI Library
#1

[eluser]Unknown[/eluser]
Hi!

I need to use this Class in a CI 2.1 project, and I would like to know how to convert it to work on CI.

Code: http://pastebin.com/HKTvWsGK

I tried this:

I copied the class php file to the application/libraries/ folder, and then wrote this in a controller:

Code:
$this->load->helper('file');
        $json = read_file('assets/js/config.json');

        $config = 'var configFile = ' . $json;

        $this->load->library('JavaScriptPacker');
        $myPacker = new JavaScriptPacker($config);
        $packed = $myPacker->pack();

        echo $packed;

But I get this Warning message when I run it:
Quote:A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for JavaScriptPacker::__construct(), called in /var/www/myapp/system/core/Loader.php on line 1099 and defined

Filename: libraries/JavaScriptPacker.php

Line Number: 86

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: _script

Filename: libraries/JavaScriptPacker.php

Line Number: 87

Then after that error message, the correct output is shown. But don't know how to avoid the error message.

Any ideas?

Thanks!
#2

[eluser]InsiteFX[/eluser]
Your loading the library but not passing the config into it!
Code:
$this->load->library('JavaScriptPacker', $config);

But it wont work because it has another class in it.

You can use the include statement to include it and try that.

#3

[eluser]Bhashkar Yadav[/eluser]
@InsiteFX: yes, there are 2 classes.
it can also work by creating 2 custom library files for JavaScriptPacker and ParseMaster as second class isn't extending first one.
#4

[eluser]Unknown[/eluser]
Thanks InsiteFX and Bhashkar

In terms of performance, speed, best practices, etc, what would be better to do?

Do a normal include and call the functions as the documentation shows, or create separate libraries of both JavaScriptPacker and ParseMaster?

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB