Welcome Guest, Not a member yet? Register   Sign In
load non-class library
#1

[eluser]Unknown[/eluser]
I have a library called "lib.php"

this is the content

<?php
function abc()
{
echo 'kkkk';
}
?>

I tried $this->load->file to load the library with absolute and relative path

the lib.php still not be loaded

how to load this library properly?
#2

[eluser]pbflash[/eluser]
Libraries need to be class files. See the user guide on creating your own libraries.

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

[eluser]Kristories[/eluser]
Code:
class Example_lib{
   public function abc()
   {
      return 'kkkk';
   }
}

Using
Code:
$this->load->library('example_lib');
echo $this->example_lib->abc();
#4

[eluser]xerobytez[/eluser]
If you just need a few functions without a class then you should look into using a helper.

http://ellislab.com/codeigniter/user-gui...lpers.html
#5

[eluser]Unknown[/eluser]
[quote author="xerobytez" date="1331268916"]If you just need a few functions without a class then you should look into using a helper.

http://ellislab.com/codeigniter/user-gui...lpers.html[/quote]

now my library is work, but still have a problem
to use the helper, the file name is required to change to xxx_helper.php

but now I intent to use a library from internet
https://github.com/openid/php-openid/downloads

and use the example directly
examples/consumer/try_auth.php


so I think I should keep everything to be original (file name, code, structure)
because I don't know what will be affected if I change it.




Theme © iAndrew 2016 - Forum software by © MyBB