簡體   English   中英

Codeigniter Session在本地主機上運行,​​但在Web服務器上不運行

[英]Codeigniter Session is working on localhost but not on web server

我正在嘗試在項目中使用會話。 它可以在localhost上運行,但不能在Web服務器上運行。 我在stackoverflow和ellislab中閱讀了一些有關此的文章,但不適用於我的項目。 可能的問題是關於創建輔助類。

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

class Memberlogin extends CI_Controller {

//protected $CI;

function __construct()
{
    $CI =& get_instance();

    parent::__construct();

    $CI->load->library('session');
    //$this->load->library('form_validation');
    //$this->load->helper(array('form', 'url'));
    $CI->load->helper('date');
    $CI->load->helper('ip_address');
    $CI->load->model('Sql_model');
}

現在錯誤是:

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Line Number: 14

A PHP Error was encountered

Severity: Error

Message: Call to a member function library() on a non-object

Line Number: 14

試試這個代碼,

function __construct()
{
    parent::__construct();

    $this->load->library('session');
    $this->load->helper('date');
    $this->load->helper('ip_address');
    $this->load->model('Sql_model');
}

如果class在controllers目錄中,則可以通過擴展CI_Controller並使用$this直接獲取CI實例。

比,嘗試不調用get_instance()函數。 就像文檔說的那樣:

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

class Memberlogin extends CI_Controller {

//protected $CI;

function __construct()
{
    parent::__construct();

    $this->load->library('session');
    //$this->load->library('form_validation');
    //$this->load->helper(array('form', 'url'));
    $this->load->helper('date');
    $this->load->helper('ip_address');
    $this->load->model('Sql_model');
}

這會讓你發瘋。 但它有效。

autoload.php

$autoload['libraries'] = array('database', 'session');
$autoload['helper'] = array('url','date','ip_address');

__constructor加載加載模型

public function  __construct()
{
    parent::__construct();
    $this->load->model('Sql_model');
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM