CodeIgniter Forums
Loading custom library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Loading custom library (/thread-59468.html)

Pages: 1 2


Loading custom library - El Forum - 10-09-2013

[eluser]mzvasiq[/eluser]
I created a Custom Library and saved it in application/libraries folder. But when i try to load the library from the Controller using the following code.

Code:
$this->load->library('BlogUtilities');

It just doesn't get loaded, so after checking the CodeIgniter's log file I came to know it's giving 'No direct script access allowed'

I don't understand why am i getting this error.

My Library has only two functions in it.


Loading custom library - El Forum - 10-09-2013

[eluser]scornaky[/eluser]
Check:
file name it is in libraries folder
filename is BlogUtilities.php
class name is BlogUtilities

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');


class BlogUtilities
{

public function test()
{
    echo "time now".time();
}

}

call
Code:
$this->load->library('BlogUtilities');
$this->blogutilities->test();



Loading custom library - El Forum - 10-09-2013

[eluser]mzvasiq[/eluser]
Ya it's exactly the same, i crossed checked everything. I don't know why I'm still getting that error.

There's no .htaccess file in the folder, is it due to that ?




Loading custom library - El Forum - 10-09-2013

[eluser]scornaky[/eluser]
in libraries?
I don`t have this kind of thing thereSmile.

But.. i`m saying again : filename is .php ? Not "BlogUtilities.php.txt"

Take a look in your host or in windows : view extensionSmile

"blogutilities" name is lowercase ? - in call



Loading custom library - El Forum - 10-09-2013

[eluser]mzvasiq[/eluser]
Yea filename is in .php extension.

And yes even the Filename is being called correctly....




Loading custom library - El Forum - 10-09-2013

[eluser]scornaky[/eluser]
make a test: use in autoload

Code:
$autoload['libraries'] = array('blogutilities');  //to check
then call
Code:
$this->blogutilities->test();

is working?




Loading custom library - El Forum - 10-09-2013

[eluser]mzvasiq[/eluser]
I had tried that too... even that's not working

In the log it says

Code:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');



Loading custom library - El Forum - 10-09-2013

[eluser]scornaky[/eluser]
[quote author="mzvasiq" date="1381324972"]I had tried that too... even that's not working

In the log it says

Code:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
[/quote]

what you type in URL in browser?


Loading custom library - El Forum - 10-09-2013

[eluser]mzvasiq[/eluser]
I don't type anything in the browser. There's a function in my Controller which loads this Library and calls the function directly.




Loading custom library - El Forum - 10-09-2013

[eluser]scornaky[/eluser]
yes Smile...
And your controller extend extends CI_Controller ?

Code:
class MY_Controller extends CI_Controller { }

or try this:

Code:
$this->CI =& get_instance();
$this->CI->load->library('blogutilities');