• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it okay to use require_once for libraries which aren't CI 'compatible'?

#1
[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?

#2
[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.

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

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

See more:

http://ellislab.com/codeigniter/user-gui...aries.html

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

#4
[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.

#5
[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);

#6
[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.

#7
[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!

#8
[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?

#9
[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...

#10
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.