“订单子句”中的CI_SESSION未知表

时间:2014-04-23 12:54:38

标签: codeigniter session

我使用数据库表来存储ci_session。这是我的控制器:

public function displayAllArticles() 
    {
        // custom limit, set in zconfig for all tables
        $customLimit = $this->config->item('articles_per_page');
        // get the total number or records
        $totalARTresults = $this->db->get('article')->num_rows();
        // set the paging variables
        if ($this->uri->segment(4) !="") 
        { 
            $limit = $this->uri->segment(4); 
        } else { 
            $limit = $customLimit; 
        } 
        $offset = 5; 
        $offset = $this->uri->segment(5); 
        $this->db->limit($limit, $offset);
        // line bellow is the offending line <<<<<<<<<<<<<<<<<<<<<<<<
        $this->db->order_by('articlecategoryID desc, articleSorder asc'); 
        $data['articles'] = $this->articlesModel->get_with_category();
        // session variables bellow are used in the view, for the 
        // code that display the message: Displaying x to y from total of z records

        $this->session->set_userdata('totalARTresults', $totalARTresults);
        $this->session->set_userdata('limit', $limit);
        $this->session->set_userdata('offset', $offset);  
        $data['articles'] = array_splice($data['articles'], $offset, $limit);
        // paging configuration
        $this->load->library('pagination');
        $config['base_url'] = site_url('/backEnd/articles/displayAllArticles/'.$limit.'/');
        $config['total_rows'] = $totalARTresults;
        $config['per_page'] = $limit;
        $config['uri_segment'] = 5;
        $config['full_tag_open'] = '<div class="dataTables_paginate paging_bootstrap pagination"><ul>';
        $config['full_tag_close'] = '</ul></div>';
        $config['cur_tag_open'] = '<li><a href=# style="color:#ffffff; background-color:#258BB5;">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        // initialize the paging
        $this->pagination->initialize($config); 
        // create & load the variables needed for the view 
        $errorMessage = '';
        $data['main_content'] = 'articles/articles';
        $data['title'] = 'Articles';
        $this->load->vars($data,$errorMessage);
        $this->load->vars($this->currentUser);
        $this->load->view('backOffice/template');  
    }   // end of function displayAllArticles

当我调用此函数时,我收到错误消息:

错误号码:1054 'order clause'中的未知列'article.articlecategoryID' 更新ci_sessions SET last_activity = 1398256604,`...........

我搜索了这个网站,我发现了这个: CI_session and Error Number: 1054 (Unknown column ...) 但解决方案:$ this-&gt; db-&gt; _reset_write(); 不起作用。

那里的作者说: $这 - &GT;会话而&GT;用户数据(); $这 - &GT;会话而&GT; set_userdata(); 等等... 必须在执行你自己的CRUD之前/之后使用($ this-&gt; db-&gt; ...),但是无论我在哪里移动会话代码,我都会得到同样的错误。

任何人都能帮我一把吗?我知道我可以删除控制器中的order_by clausule,但是如果我这样做的话,我还有很多遗留代码需要更改。

任何帮助都将深表感谢。 问候,约翰

1 个答案:

答案 0 :(得分:0)

确保以下事项 -


1)自动加载库的顺序(config / autoload.php)

$autoload['libraries'] = array('database','upload','session','form_validation');
// session loaded after database library


2)拥有ci_sessions表格

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
   session_id varchar(40) DEFAULT '0' NOT NULL,
   ip_address varchar(45) DEFAULT '0' NOT NULL,
   user_agent varchar(120) NOT NULL,
   last_activity int(10) unsigned DEFAULT 0 NOT NULL,
   user_data text NOT NULL,
   PRIMARY KEY (session_id),
   KEY `last_activity_idx` (`last_activity`)
);

//Refer: http://ellislab.com/codeigniter/user-guide/libraries/sessions.html
// ensure table name: ci_sessions


3)允许在ci_sessions

中使用config/config.php表格
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';    // ensure table name: ci_sessions
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] =  86400 * 30; //30 days