CodeIgniter Forums
Is it okay to use require_once for libraries which aren't CI 'compatible'? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Is it okay to use require_once for libraries which aren't CI 'compatible'? (/showthread.php?tid=49769)

Pages: 1 2


Is it okay to use require_once for libraries which aren't CI 'compatible'? - El Forum - 03-02-2012

[eluser]dallen33[/eluser]
Code:
require_once($_SERVER['DOCUMENT_ROOT'].'\directory\application\libraries\simple_html_dom.php');
require_once($_SERVER['DOCUMENT_ROOT'].'\directory\application\libraries\url_to_absolute.php');
Also, is there a better way I can write that?


Is it okay to use require_once for libraries which aren't CI 'compatible'? - El Forum - 03-02-2012

[eluser]Aken[/eluser]
What's not compatible about it? All you need to do is make sure the file name and class name match the name of the library you're trying to load, then you can use $this->load->library() like normal.


Is it okay to use require_once for libraries which aren't CI 'compatible'? - El Forum - 03-02-2012

[eluser]porquero[/eluser]
The correct method is:

$this->load->library('class name');

See more:

http://ellislab.com/codeigniter/user-guide/general/libraries.html

Is not neccesary that a library compatible with CI. Only use it.
Must be a class only.


Is it okay to use require_once for libraries which aren't CI 'compatible'? - El Forum - 03-02-2012

[eluser]dallen33[/eluser]
[quote author="Aken" date="1330718634"]What's not compatible about it? All you need to do is make sure the file name and class name match the name of the library you're trying to load, then you can use $this->load->library() like normal.[/quote]
simple_html_dom includes two classes in one file. If I load->library, it won't work.

And url_to_absolute.php isn't even in a class.


Is it okay to use require_once for libraries which aren't CI 'compatible'? - El Forum - 03-02-2012

[eluser]dallen33[/eluser]
My bad, it actually does work:
Code:
$this->load->library(array('form_validation', 'simple_html_dom'));

But to use it, my code has to look like this:
Code:
$html = file_get_html($url);

I was originally trying:
Code:
$html = $this->simple_html_dom->file_get_html($url);



Is it okay to use require_once for libraries which aren't CI 'compatible'? - El Forum - 03-02-2012

[eluser]Mauricio de Abreu Antunes[/eluser]
[quote author="dallen33" date="1330718994"]My bad, it actually does work:
Code:
$this->load->library(array('form_validation', 'simple_html_dom'));

But to use it, my code has to look like this:
Code:
$html = file_get_html($url);

I was originally trying:
Code:
$html = $this->simple_html_dom->file_get_html($url);
[/quote]<- It's not possible because your lib does not extend CI.


Is it okay to use require_once for libraries which aren't CI 'compatible'? - El Forum - 03-02-2012

[eluser]dallen33[/eluser]
[quote author="Mauricio de Abreu Antunes" date="1330719189"][quote author="dallen33" date="1330718994"]My bad, it actually does work:
Code:
$this->load->library(array('form_validation', 'simple_html_dom'));

But to use it, my code has to look like this:
Code:
$html = file_get_html($url);

I was originally trying:
Code:
$html = $this->simple_html_dom->file_get_html($url);
[/quote]<- It's not possible because your lib does not extend CI. [/quote]Crap, that's what it was all along. Couldn't figure it out. Thanks Mauricio!


Is it okay to use require_once for libraries which aren't CI 'compatible'? - El Forum - 03-02-2012

[eluser]Mauricio de Abreu Antunes[/eluser]
You are welcome, dude.
When you extend CI in your lib and turning this a class, you can manipulate other CI classes into your required lib. :-) Did you get the point?


Is it okay to use require_once for libraries which aren't CI 'compatible'? - El Forum - 03-02-2012

[eluser]dallen33[/eluser]
[quote author="Mauricio de Abreu Antunes" date="1330719427"]You are welcome, dude.
When you extend CI in your lib and turning this a class, you can manipulate other CI classes into your required lib. :-) Did you get the point?[/quote]Actually I don't get it now. How to you extend a library? I'm not extending a core library...


Is it okay to use require_once for libraries which aren't CI 'compatible'? - El Forum - 03-02-2012

[eluser]Mauricio de Abreu Antunes[/eluser]
As an added bonus, CodeIgniter permits your libraries to extend native classes if you simply need to add some functionality to an existing library. Or you can even replace native libraries just by placing identically named versions in your application/libraries folder.

In summary:

You can create entirely new libraries.
You can extend native libraries.
You can replace native libraries.


Ok, you are cratin a new library, i know, but you can extend it from a similar library.