Welcome Guest, Not a member yet? Register   Sign In
Problem in loading model , strange output is displayed
#1

[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
class Login extends Controller {

    function Login()
    {
        
        parent::Controller();
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->model('Admin_Model');
        $this->load->library('validation');
        $this->load->library('email');
        
    }
    
    function index()
    {
        
       $this->load->view('login_view',$data);
        
    }
    
}

And my Model class is
Code:
class Admin_Model extends Model
{
    /**
     * Enter description here...
     *
     * @return Admin_Model
     */
    function Admin_Model()
    {
        parent::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);
$model = ucfirst($model);
$CI->$name = new $model();
$CI->$name->_assign_libraries();


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
#2

[eluser]tomcode[/eluser]
Try this :

1. name Your model with only the first letter upper case
Code:
class Admin_model extends Model

2. set it's file name to all lower case :
admin_model.php

3. load the model with :
Code:
$this->load->model('admin_model');

4. use the model with :
Code:
$this->admin_model->my_method();
#3

[eluser]sheri.nust[/eluser]
I have also tried your approach ,
but still its not working...
But i have used the same code on live server.

Now on localhost i am facing this issue ,

Anyhow this is my htaccess file, May be there is some issue in it

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>
#4

[eluser]tomcode[/eluser]
It has nothing to do with Your .htaccess file

Quote:The complete error attached in file is below

...

Looks like the file is found and read, but not treated as PHP file, instead printed, very strange ...
#5

[eluser]sheri.nust[/eluser]
So what you think ,
what would be the problem ,
any idea , as i have badly hanged with it
#6

[eluser]tomcode[/eluser]
I have never had that, I'd try to create a new file, check the PHP declaration, ask on the XAMPP forum.
#7

[eluser]abedzilla[/eluser]
Did you forget to add the php open tag in your model's source
Code:
&lt;?php

or are you using the short open tag like:
Code:
&lt;?

check your short_open_tag configuration in your php.ini file
#8

[eluser]InsiteFX[/eluser]
For one, this is wrong!
Code:
// wrong
$this->load->library('validation');

// should be
$this->load->library('form_validation');

Models have the first letter capitalized in the class the model is then save to file with all lowercase letters.

Loading a model:
Code:
$this->load->model('admin_model');

InsiteFX
#9

[eluser]sheri.nust[/eluser]
I solved the problem ,
that was due to
wrong opening tag of PHP

In my model class,i replaced
Code:
&lt;?
with
Code:
&lt;?php

But i have used the same code on live server and it was working,

I wonder why
Code:
&lt;?php
tag is not working on my local xampp server
#10

[eluser]Dahak-II[/eluser]
What abedzilla said...

The most obvious thing to check would be your PHP.INI files.

Compare the lines referring to short_open_tag.

One machine seems to have it set to Off.




Theme © iAndrew 2016 - Forum software by © MyBB