![]() |
Problem in loading model , - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Problem in loading model , (/showthread.php?tid=38587) Pages:
1
2
|
Problem in loading model , - El Forum - 02-12-2011 [eluser]sheri.nust[/eluser] I am wandering why this type of error is coming on local host , as i have tried the same below mentioned approach many time on live server. Also i have allowed url rewriting on apache server and i am using XAMPP on my local machine. I have installed CodeIgniter_1.7.3 version on my machine My code is as follows Code: <?php And my Model class is Code: class Admin_Model extends Model If i dont load my model using Code: $this->load->model('Admin_Model'); then everything works fine and view is loaded . But when i try to load my model class, strange output is displayed with an error message that Fatal error: Class 'Admin_model' not found in C:\xampp\htdocs\emsystem\system\libraries\Loader.php on line 184 And when i opened the file Loader.php file and went to line 184 ,i found following code Code: require_once(APPPATH.'models/'.$path.$model.EXT); The complete error attached in file is below ERROR db->where('nick',$strArr["Username"]); $this->db->where('password',$strArr["Password"]); $type=array('admin','agent'); $this->db->where_in('type',$type); $this->db->where('status','active'); $query = $this->db->get('User'); $list = array(); foreach ($query->result() as $row) return $row; //$str = $this->db->last_query(); } /*---------------------------------*/ /** * Function to Get user(basic user) by id * Dev: khurram * @package PointOfSale * @since * @filesource */ function getUserByID($id) { $this->db->where('id',$id); $query = $this->db->get(POS_PREFIX.'_users'); $list = array(); //$html=''; foreach ($query->result() as $row) { $list[] = $row; } // Return Array return $list; } /*---------------------------------*/ /** * Function to Add Admin * Dev: khurram * @package PointOfSale * @since * @filesource */ function addAdmin($dataArray) { if (!$this->validateEmail($dataArray["Email"])) { $data = array( 'FullName' => $dataArray["FullName"], 'Address' => $dataArray["Address"], 'Email' => $dataArray["Email"], 'Password' => md5($dataArray["Password"]), 'Address' => $dataArray["Address"], 'Phone' => $dataArray["Phone"], 'Mobile' => $dataArray["Mobile"] ); $this->db->insert('admin', $data); return mysql_insert_id(); } else return 0; } function checkUserName($userName){ $this->db->where('Username',$userName); $query = $this->db->get(DB_PREFIX.'Users'); $res = $query->result(); if(empty($res)){ return true; }else{ return false; } } function checkUserEmail($email){ $this->db->where('Email',$email); $query = $this->db->get(DB_PREFIX.'Users'); $res = $query->result(); if(empty($res)){ return true; }else{ return false; } } function registerUser($data){ if($this->db->insert(DB_PREFIX.'Users', $data)){ $user_id = $this->db->insert_id(); return $user_id; } } function insertActivationKey($userID , $key){ $data['user_id'] = $userID; $data['activation_key'] = $key; $this->db->insert(DB_PREFIX.'activation', $data); } function checkKey($key){ $this->db->where('activation_key',$key); $query = $this->db->get(DB_PREFIX.'activation'); $res = $query->result(); if(!empty($res)){ return $res; }else{ return false; } } function deleteActivation($key){ $this->db->where('activation_key',$key); $this->db->delete(DB_PREFIX.'activation'); return true; } function updateLevel($id){ $this->db->where('UserID' , $id); $data['Status'] = 'Active'; $this->db->update(DB_PREFIX.'Users' , $data); return true; } } ?> Fatal error: Class 'Admin_model' not found in C:\xampp\htdocs\emsystem\system\libraries\Loader.php on line 184 Problem in loading model , - El Forum - 02-13-2011 [eluser]osci[/eluser] Code: class Admin_model extends Model Code: $this->load->model('Admin_model'); As in user_guide Code: Class names must have the first letter capitalized with the rest of the name lowercase. Make sure your class extends the base Model class. Problem in loading model , - El Forum - 02-13-2011 [eluser]sheri.nust[/eluser] I have followed your approach , but still not working The problem is CI is not working on XAMPP in windows 7, The problem comes in C:\xampp\htdocs\emsystem\system\libraries\Loader.php file , as model class not found at below mentioned code in Loader.php. Code: require_once(APPPATH.'models/'.$path.$model.EXT); I think it does not allow to create model class , Looks like the file is found and read, but not treated as PHP file, instead printed, very strange... I am now trying to set VHOST in XAMPP , or may be there is some problem in ht-access file . Problem in loading model , - El Forum - 02-13-2011 [eluser]InsiteFX[/eluser] I run xampp on windows 7 Pro and have no problems with CI 172, 173 or 2.0 1) Download and re-install CodeIgniter. 2) Your application/config/config.php base_url path is wrong. 3) You did not set the system and application folder paths right in index.php InsiteFX Problem in loading model , - El Forum - 02-13-2011 [eluser]sheri.nust[/eluser] 1) Download and re-install CodeIgniter. I have now downloaded and install new version CodeIgniter_2.0.0 2) Your application/config/config.php base_url path is wrong. MY base_url is $config['base_url'] = 'http://localhost/CI_2/'; and i am loading images and css using the same base_url in my view, no problem in that. But when i load my model the error comes Class 'Administrator_model' not found in C:\xampp\htdocs\CI_2\system\core\Loader.php on line 199 My model class is below Code: <? 3) You did not set the system and application folder paths right in index.php Here is index.php file Code: <?php Kindly if you have time can u come online on skype , and add me khurram.shairyar. I would be grateful Problem in loading model , - El Forum - 02-13-2011 [eluser]InsiteFX[/eluser] Show us your directory structure. I have CI 2.0 working with no problems, so you have to have something wrong some place. InsiteFX Problem in loading model , - El Forum - 02-13-2011 [eluser]sheri.nust[/eluser] I have placed project files here -->C:\xampp\htdocs\CI_2 -->C:\xampp\htdocs\CI_2\application\controllers -->C:\xampp\htdocs\CI_2\application\views -->C:\xampp\htdocs\CI_2\application\models core files are at -->C:\xampp\htdocs\CI_2\system My htaccess file for this project is at -->C:\xampp\htdocs\CI_2\application Code: <IfModule mod_rewrite.c> Problem in loading model , - El Forum - 02-13-2011 [eluser]intractve[/eluser] The .htaccess should be in the root of your project, "C:\xampp\htdocs\CI_2" where the index.php is and not inside the application folder. Problem in loading model , - El Forum - 02-13-2011 [eluser]InsiteFX[/eluser] For CI 2.0 you can leave this like so it will auto fill it in. Code: $config['base_url'] = ''; InsiteFX Problem in loading model , - El Forum - 02-14-2011 [eluser]sheri.nust[/eluser] The problem is solved now ![]() thats was just a minor mistake and i wonder no one noticed it . Anyhow In my model class Now I have replaced PHP starting tag Code: <? with tag Code: <?php And also include Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); So my model class now is Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Also i have one question that in my model class, even if i dont use closing PHP tag , at the end of class , everything works fine, as following code Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Is this is correct according to the convention of CI model? |