user3453318
user3453318

Reputation: 15

loading configuration information in to the library

I have my configuration detail in config.php as follows:

$config["system_images"] = "path to the folder";

I have created my own library FORM, in which I need to use above value in $config["system_images"]. So I called it, $this->config->item("system_images"). I don't load any configuration file, because I use the default configuration file. But following error occurred:

Parse error: syntax error, unexpected '$this' (T_VARIABLE) in D:\MYSERVER\wamp\www\ci\application\libraries\Form.php on line 3

How should I use values defined in configuration file in my own library?

Upvotes: 0

Views: 65

Answers (2)

TazGPL
TazGPL

Reputation: 3748

Unexpected T_VARIABLE is a parse error, meaning that code syntax or structure is not valid. This error usually occurs because of missing semicolon or bracket somewhere before it's triggered.

In your case, if it's line 3, then check that you closed all brackets properly in line 2 and 1, or that line 2 is not missing the semicolon.

Upvotes: 1

isawhat
isawhat

Reputation: 151

You need to load the CodeIgniter super object in to your library.

You can do it per function this way:

$CI =& get_instance();
$CI->config->item("system_images");

Or do it this way:

class yourclass extends CI_Library {

    private $CI;


    function __construct() {

        $this->CI =& get_instance();
    }

    function youfunction() {
        $this->CI->config->item("system_images");

    }
}

Upvotes: 0

Related Questions