未定义的属性:start_up :: $ uri

时间:2014-04-01 15:08:15

标签: php codeigniter

我有这个问题,而且我不知道如何解决它。

Message: Undefined property: start_up::$uri
Filename: libraries/start_up.php
Line Number: 25
Fatal error: Call to a member function segment() on a non-object in C:\Program Files\wamp\www\sooq\application\libraries\start_up.php on line 25

line 25是以下代码:

if ($this->CI->config->item('close') == 1 && $this->uri->segment('1') != 'Admin' && !$this->ion_auth->is_admin()) {
            redirect(base_url() . 'home/close', '
}

以下是有问题的方法:

function _init() {
        $this->CI->load->model('start_up_model');

        foreach ($this->CI->start_up_model->get_config()->result() as $config) {
            $this->CI->config->set_item($config->Var_Name, $config->Var_Value);
        }
        /* ---->>>new_settings */
        $setting = $this->CI->start_up_model->get_newsetting();
        foreach ($setting as $key => $value) {
            $this->CI->config->set_item($key, $value);
        }

        if ($this->CI->config->item('close') == 1 && $this->uri->segment('1') != 'Admin' && !$this->ion_auth->is_admin()) {
            redirect(base_url() . 'home/close', 'refresh');
        }

        if ($this->CI->session->userdata('lang')) {
            $this->CI->lang->load($this->CI->session->userdata('lang'), $this->CI->session->userdata('lang'));
            $this->CI->session->set_userdata('lang', $this->CI->session->userdata('lang'));
            if ($this->CI->session->userdata('year')) {
                $this->CI->session->set_userdata('year', $this->CI->session->userdata('year'));
            } else {
                $this->CI->session->set_userdata('year', '2013');
            }
        } else {
            $this->CI->lang->load('arabic', 'arabic');
            $this->CI->session->set_userdata('lang', 'arabic');
            if ($this->CI->session->userdata('year')) {
                $this->CI->session->set_userdata('year', $this->CI->session->userdata('year'));
            } else {
                $this->CI->session->set_userdata('year', '2013');
            }
        }
    }

$this->CI以这种方式定义:

$this->CI = &get_instance();

1 个答案:

答案 0 :(得分:1)

当您在自定义库中使用CI实例时,必须通过实例调用所有本机库,包括URI类。除了在调用URI类时,您在代码中的任何位置都可以正确执行此操作。而不是

$this->uri->segment('1')

执行:

$this->CI->uri->segment('1')