Welcome Guest, Not a member yet? Register   Sign In
CodeIgnitor problem
#1

[eluser]fariad22[/eluser]
I was learning a tutorial and i found this problem but not understanding wht is ths?
Fatal error: Cannot redeclare class Users in D:\xampp\htdocs\projects\Clients\CodeIgnitor\CodeIgniter_1.7.1\system\application\models\Users.php on line 80
------------------
The code is here
-----
for model class
class Users extends Model{

function Users(){

// call the Model constructor

parent::Model();

// load database class and connect to MySQL

$this->load->database();

}

function getAllUsers(){

$query=$this->db->get('users');

if($query->num_rows()>0){

// return result set as an associative array

return $query->result_array();

}

}

function getUsersWhere($field,$param){

$this->db->where($field,$param);

$query=$this->db->get('users');

// return result set as an associative array

return $query->result_array();

}

// get total number of users

function getNumUsers(){

return $this->db->count_all('users');

}

}

----
for controller class
---
class Users extends Controller{

function Users (){

// load controller parent

parent::Controller();

// load 'Users' model

$this->load->model('Users');

}

function index(){

// store data for being displayed on view file

$data['users']=$this->Users->getUsers();

$data['numusers']=$this->Users->getNumUsers();

$data['title']='Displaying user data';

$data['header']='User List';

// load 'users_view' view

$this->load->view('users_view',$data);

}

}
please tell me wht actually is and i don't get the logic behind this.
#2

[eluser]GSV Sleeper Service[/eluser]
you can't have two classes with the same name (unless you use namespaces, which is never going to happen with CI)
rename your Users model to something like Users_model and all should be fine
#3

[eluser]fariad22[/eluser]
In CI, is it neccessary to associate the name of the file with the class you are developing?
if yes then i changed the names of the files but the code didn't work?
#4

[eluser]Yash[/eluser]
Please read user guide before u get started..all ans you will find there.




Theme © iAndrew 2016 - Forum software by © MyBB