CodeIgniter Forums
CodeIgnitor problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: CodeIgnitor problem (/showthread.php?tid=21545)



CodeIgnitor problem - El Forum - 08-13-2009

[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.


CodeIgnitor problem - El Forum - 08-13-2009

[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


CodeIgnitor problem - El Forum - 08-13-2009

[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?


CodeIgnitor problem - El Forum - 08-13-2009

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