2015-11-24 17 views
0

我想在我的控制器中聲明一個變量。我不得不使用$ CI,因爲沒有在活動服務器上看到會話文件。

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

class Memberlogin extends CI_Controller { 
private $CI =& get_instance(); 
function __construct() 
{ 

    parent::__construct(); 

    $CI->load->library('session'); 
    . 
    . 
} 

但錯誤是

Severity: Parsing Error 

Message: syntax error, unexpected '&' 
+0

可能是這個問題東陽會議不能寫,嘗試申請變更/配置/ config.php文件$配置[「sess_save_path」 ] =任何可寫的FolderPath –

+0

我檢查了文件夾。文件夾是可寫的 – ofozdmr

回答

1

試試這個,但並不需要在控制器使用get_instance()。當我們使用庫,助手等

基本上get_instance()使用...

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

    class Memberlogin extends CI_Controller { 
    private $CI; 
    function __construct() 
    { 

      parent::__construct(); 
      $this->CI =& get_instance(); 
      $this->CI->load->library('session'); 

    } 
+0

當我嘗試這個主頁只是刷新自己。我有關於會話的問題。活服務器項目上無法訪問會話文件。 – ofozdmr

+0

打印會話並檢查會發生什麼? –

+0

我應該在視圖中打印嗎? – ofozdmr

1

如Arvind的使用get_instance只需要庫和助手中提及。在笨,你只需要調用$this->所以您的代碼將被改寫爲以下

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

class Memberlogin extends CI_Controller { 

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

     $this->load->library('session'); 
    } 

} 
+0

你是真的 –