Welcome Guest, Not a member yet? Register   Sign In
[solved]paths in external library
#1

[eluser]quasiperfect[/eluser]
hi

i want to use securimage with codeigniter
my folders look like this
system
application
fonts
etc
i placed the library in application/libraries
inside the library there are some variables that define the paths to the fonts
like this
Code:
var $gd_font_file = 'fonts/bubblebath.gdf'; var $ttf_file = "fonts/elephant.ttf";

how can i define the paths in the library so it can load the fonts correctly ?
#2

[eluser]xwero[/eluser]
There is a fonts directory in the system directory which is easily accessed by
Code:
var $gd_font_file = BASEPATH.'fonts/bubblebath.gdf'; var $ttf_file = BASEPATH.'fonts/elephant.ttf';
#3

[eluser]quasiperfect[/eluser]
and how do i pass BASEPATH to the library ? or for that matter any var or constant

i do
Code:
$ci =& get_instance();
and then ?

i call the library in a controller like this
Code:
<?php
class ShowCaptcha extends Controller {

    function ShowCapcha()
    {
        parent::Controller();
    }
    
    function index()
    {
        $this->load->library('securimage');
        $this->securimage->show();
    }
}
?>
#4

[eluser]xwero[/eluser]
if you load the library the constant will automagically be visible for the library. For variables it depends on the when. If you want to add parameters on loading you can use the second argument. Of course your library has to process it in a constructor. Otherwise you just add variables as parameters to the methods that need it.
#5

[eluser]quasiperfect[/eluser]
i give up i can't get it to work with ci and i'm not able to debug it from inside ci. and i'm preaty sure the constant isn't magicly there... or maybe i'm wrong
#6

[eluser]Mirage[/eluser]
you are wrong. constants are GLOBAL in PHP. BASEPATH is defined in index.php.

What you need to do is to configure the secureimage paths you mentioned to be prefixed with BASEPATH as illustrated by xwero. There's still a potential that your path is mangled or perhaps not readable/writeable by secureimage because of permission issues.

Not sure what you mean when you say you can't debug it from inside ci. First of all CI does have it's own logging mechanism. If you don't use that it's always useful to check the apache error_log. Finally there's nothing wrong with the good old 'echo'. Add a line after your var definition in the library:

Code:
var $gd_font_file = 'fonts/bubblebath.gdf'; var $ttf_file = "fonts/elephant.ttf";
var_dump($gd_font_file, $ttf_file);

to make sure your paths are correct. There may be further down the call stack.

Cheers!
#7

[eluser]xwero[/eluser]
Can you show the constructor you have of the library?
Actually there is nothing magical about the constants. When you load a library it means it gets included and because the BASEPATH constant is defined before the loading of the class it is known to the library.
#8

[eluser]quasiperfect[/eluser]
thanks for responding after some banging on the wall i solved most of the problems
one little thing remains inside a function of securimage class i have
Code:
$CI =& get_instance();
$this->code_entered = $code;
$CI->log_message('error',$this->code_entered);

and i get a fatal error: Call to undefined method
how can i call log_message function inside the lib ?
#9

[eluser]Mirage[/eluser]
log_message is a global function, not a controller method you simply call it from 'anywhere' like this:
Code:
log_message('error',$this->code_entered);
#10

[eluser]quasiperfect[/eluser]
thanks now everything works like a charm i will post a tutorial on wiki (so everyone can use it) when i'm done




Theme © iAndrew 2016 - Forum software by © MyBB