Welcome Guest, Not a member yet? Register   Sign In
Fatal Error when adding libraries (Solved)
#1

[eluser]sagarv[/eluser]
Hi, I am new to CI, I have installed the system and everything seems to be working fine.

However each time I try to install a 3rd party library, I get some sort of fatal or parse error like below:
http://mydiscobox.com/account/

I've tried to install all three of these and all encounter a fatal/parse error of some sort (I dont modify the files at all)
- Tank_Auth
- Ion_Auth
- UhOh

It seems to have issues loading the libraries

I have this controller working which doesnt use an add-on library so I'm not sure what the problem is
http://mydiscobox.com/account/

Can anyone help!?

Thanks !!
#2

[eluser]Prophet[/eluser]
Could you post the code around line 15 of account.php?

The error means you are trying to do something like..
Code:
$foo->function()
..when $foo isn't an object.

var_dump($foo) and print_r($foo) are useful for debugging things like this.
#3

[eluser]sagarv[/eluser]
Hi, the code at line 15 is:

Code:
if (!$this->tank_auth->is_logged_in()) {

Here is the whole file, it is from Tank_Auth (I haven't modified it at all)


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

class Account extends Controller
{
    function __construct()
    {
        parent::__construct();

        $this->load->helper('url');
        $this->load->library('tank_auth');
    }

    function index()
    {
        if (!$this->tank_auth->is_logged_in()) {
            redirect('/auth/login/');
        } else {
            $data['user_id']    = $this->tank_auth->get_user_id();
            $data['username']    = $this->tank_auth->get_username();
            $this->load->view('account', $data);
        }
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

Thanks for your help
#4

[eluser]Prophet[/eluser]
Make sure that tank_auth is actually loaded.

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

You can also put tank_auth into the $autoload['libraries'] array in config/autoload.php.
#5

[eluser]Jelmer[/eluser]
It's strange, your code should fail much sooner. The first line loading the parent constructor is impossible:
Code:
parent::__construct();
That should read:
Code:
parent::Controller();
And should throw an error now because there is no method "__construct()" in the Controller class. The only reason I can think of this wouldn't fail is that you're running PHP4 and __construct() isn't recognized as a constructor. You'll need to use Account() instead (same as the class itself)

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

class Account extends Controller
{
    function Account()
    {
        parent::Controller();

        $this->load->helper('url');
        $this->load->library('tank_auth');
    }

    function index()
    {
        if (!$this->tank_auth->is_logged_in()) {
            redirect('/auth/login/');
        } else {
            $data['user_id']    = $this->tank_auth->get_user_id();
            $data['username']    = $this->tank_auth->get_username();
            $this->load->view('account', $data);
        }
    }
}

/* End of file account.php */
/* Location: ./application/controllers/account.php */
#6

[eluser]sagarv[/eluser]
Hi guys, thanks for the help, I've tried that code and am now seeing a parse error. This is the same parse error I got when I installed Ion Auth and UhOh, there are no parse errors any of the files as I'm using yet they keep showing up so I can't get anything working

http://mydiscobox.com/account/

I have another controller here which doesn't use any 3rd party files which seems to work

http://mydiscobox.com/signup/
#7

[eluser]sagarv[/eluser]
Here is the Tank_Auth.php file, line 24

Code:
private $error = array();






Code:
{
    private $error = array();

    function __construct()
    {
        $this->ci =& get_instance();

        $this->ci->load->config('tank_auth', TRUE);

        $this->ci->load->library('session');
        $this->ci->load->database();
        $this->ci->load->model('tank_auth/users');

        // Try to autologin
        $this->autologin();
    }

etc..
#8

[eluser]Prophet[/eluser]
[quote author="Jelmer" date="1280131950"]It's strange, your code should fail much sooner. The first line loading the parent constructor is impossible:
Code:
parent::__construct();
That should read:
Code:
parent::Controller();
And should throw an error now because there is no method "__construct()" in the Controller class.[/quote]

Does PHP not automagically find function Controller() when __construct() is called?
#9

[eluser]sagarv[/eluser]
Hey guys, after a bit of digging I've found my webserver was using PHP4, I changed it to PHP5 and everything seems to be working now!

Thanks for your help! :cheese:




Theme © iAndrew 2016 - Forum software by © MyBB