Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loading config file from library #1772

Closed
mirzadelic opened this issue Sep 4, 2012 · 3 comments
Closed

loading config file from library #1772

mirzadelic opened this issue Sep 4, 2012 · 3 comments

Comments

@mirzadelic
Copy link

Hi,
i made new file in /config/ folder render.php and have this content:

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


$config['test1']    = 'some text';

And i have library Render.php in /libraries/ folder with this content:

<?php
class Render {

    protected $CI;

    public function __construct() {

        $this->CI =& get_instance();
        $this->CI->load->config('render');
    }

    function link() {

        return $this->config->item('test1');
    }

}

Now i get error:

Message: Undefined property: Render::$config

that library is autoloaded, but config is not, becouse i will load it manualy from this library, why am i getting this error ?

@timw4mail
Copy link
Contributor

It needs to be $this->CI->config->item('test1');

@mirzadelic
Copy link
Author

Thank you, it works.

@MR-AMDEV
Copy link

make sure to use this in your class

/**
 * Enables the use of CI super-global without having to define an extra variable.
 *
 * @param $var
 *
 * @return mixed
 */
public function __get($var){
    return get_instance()->$var;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants