loading configuration information in to the library

你离开我真会死。 提交于 2020-01-16 19:16:13

问题


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?


回答1:


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");

    }
}



回答2:


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.



来源:https://stackoverflow.com/questions/22597261/loading-configuration-information-in-to-the-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!