Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Cannot redeclare class User
#1

[eluser]SamoualSys[/eluser]
Fatal error: Cannot redeclare class User in C:\xampp\htdocs\test\application\models\user.php on line 36
i have this error msg with white screen
my model code is
Code:
<?php
Class User extends CI_Model
{
  function login($user, $pass)
  {
    $this -> db -> select('id, user, password');
    $this -> db -> from('users');
    $this -> db -> where('user = ' . "'" . $user . "'");
    $this -> db -> where('password = ' . "'" . MD5($pass) . "'");
    $this -> db -> limit(1);
  
    $query = $this -> db -> get();
  
    if($query -> num_rows() == 1)
    {
      return $query->result();
    }
    else
    {
      return false;
    }
  }
  function insert_user()
    {
        $this->user   = $_POST['username']; // inser new user to data base
        $this->password = $_POST['password'];
        $this->email = $_POST['email'];
      //  $this->date    = time();

        $this->db->insert('users', $this);
        return ;
    }
    
    
    
}?>

my controler code is
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
class User extends CI_Controller {
  
  function __construct()
  {
    parent::__construct();
  }
  
  function index()
   {
   if($this->session->userdata('logged_in'))
    {
     $session_data = $this->session->userdata('logged_in');
      $userlogin['user'] = $session_data['user'];
   $this->load->view('user',$userlogin);
  }
   else
    {
      //If no session, redirect to login page
      redirect('login', 'refresh');
    }
  }}
  
?>
can you help and explain what this error mean please
#2

[eluser]SamoualSys[/eluser]
i have thought it may be becouse i use the same name of the controler and the model name so i change the name of the model to user_model but now it give me this error msg in all my application
Code:
Unable to locate the model you have specified: user
i have search all my files and change it to user_model but still give me the same error
#3

[eluser]Samus[/eluser]
[quote author="SamoualSys" date="1333706535"]i have thought it may be because i use the same name of the controler and the model name so i change the name of the model to user_model but now it give me this error msg in all my application
Code:
Unable to locate the model you have specified: user
i have search all my files and change it to user_model but still give me the same error [/quote]
Yes that was the initial problem.

But you don't seem to have changed the model file name, it needs to correspond with the class name too.

so if your model file name is now 'user_model' your model class name should be 'User_model'
#4

[eluser]InsiteFX[/eluser]
I think you need to learn PHP before trying to tackle CodeIgniter!
#5

[eluser]SamoualSys[/eluser]
thanks insiteFX i am trying to learn php i have read some book and iam using codeigniter to learn coding in with this error i have learn alot i have fix my error but dont ask me how from trying i have make it work . as i remmber i change the controller name to users and it worked .
#6

[eluser]InsiteFX[/eluser]
You can only have one class name!

Your error is stating that you are trying to load the same class a second time check your code..




Theme © iAndrew 2016 - Forum software by © MyBB