2015-10-14 41 views
-1

甲PHP錯誤遇到解析錯誤笨

嚴重性:分析錯誤

消息:語法錯誤,意想不到 '$這'(T_VARIABLE)

文件名:控制器/ user.php的

行號:6

回溯:

public function __construct() 

{ 

    parent::__construct() 

    $this->load->model('user_model', $data); 

} 

更新來自備註

<?php if(!defined('BASEPATH')) die("No direct Script Access allowed"); 

class user extends CI_Controller { 

public function index(); { 

    if(($this->session->userdata('user_name')!="")) { 

    $this->welcome(); 

} 
} 
+0

這是行號6 ?? –

+0

@DJSilver你可以點擊下面的編輯按鈕標籤並編輯你的問題。 – user4419336

+0

有問題編輯。 –

回答

1

你缺少在構造區域;

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

如果您使用笨3,你必須有類和文件名作爲大寫例如的welcome.php第一個字母class Welcome extends CI_Controller同去與模型和函數庫,

和控制器從指數public function index();

去除; user.php的

<?php if(!defined('BASEPATH')) die("No direct Script Access allowed"); 

class User extends CI_Controller { 

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

     $this->load->model('user_model');  
    } 

    public function index() { 

     if ($this->session->userdata('user_name') == TRUE) { 
      $this->welcome(); 
     } else { 

      // Just a idea make them go to error page or something 
      // Up to you. 
      $this->some_other_function(); 
     } 
    } 

    public function welcome() { 
     // Example. 
     $variable = $this->user_model->function(); 

     $this->load->view('some_view', $variable); 
    } 

    public function some_other_function() { 
     $this->load->view('another_view'); 
    } 

} 

我會通過大多數User Guide Codeigniter 3

而且笨文檔的頁面的http://www.codeigniter.com/docs

的建議閱讀10