-1

A PHP Error was encountered

Severity: Parsing Error

Message: syntax error, unexpected '$this' (T_VARIABLE)

Filename: controllers/user.php

Line Number: 6

Backtrace:

public function __construct()

{
    
    parent::__construct()
    
    $this->load->model('user_model', $data);

}

Updated From Comment

<?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(); 

} 
}
Community
  • 1
  • 1
DJ Silver
  • 1
  • 1
  • 1
  • 2

1 Answers1

1

Your missing ; in the constructor area.

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

If your using codeigniter 3 you must have the FIRST LETTER of class and file name as upper case example Welcome.php and class Welcome extends CI_Controller same goes with models and libararies.

And Controller removed ; from index 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');
   }

}

I would recommend reading through most of the User Guide Codeigniter 3

And Codeigniter Doc's Page Here http://www.codeigniter.com/docs