Welcome Guest, Not a member yet? Register   Sign In
Problem in loading model ,
#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]osci[/eluser]
Code:
class Admin_model extends Model
{
    /**
     * Enter description here...
     *
     * @return Admin_Model
     */
    function Admin_model()

// file admin_model.php

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.

The file name will be a lower case version of your class name.
#3

[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);
        $model = ucfirst($model);
                
        $CI->$name = new $model();
        $CI->$name->_assign_libraries();
        
        $this->_ci_models[] = $name;

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 .
#4

[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
#5

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

class Administrator_model extends  CI_Model
{
    /**
     * Enter description here...
     *
     * @return Administrator_model
     */
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    
    
    
    
}
?>

3) You did not set the system and application folder paths right in index.php

Here is index.php file
Code:
<?php

    error_reporting(E_ALL);


    $system_path = "system";

    $application_folder = "application";


/*
* ---------------------------------------------------------------
*  Resolve the system path for increased reliability
* ---------------------------------------------------------------
*/
    if (realpath($system_path) !== FALSE)
    {
        $system_path = realpath($system_path).'/';
    }

    // ensure there's a trailing slash
    $system_path = rtrim($system_path, '/').'/';

    // Is the system path correct?
    if ( ! is_dir($system_path))
    {
        exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
    }

/*
* -------------------------------------------------------------------
*  Now that we know the path, set the main path constants
* -------------------------------------------------------------------
*/
    // The name of THIS file
    define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));

    // The PHP file extension
    define('EXT', '.php');

    // Path to the system folder
    define('BASEPATH', str_replace("\\", "/", $system_path));

    // Path to the front controller (this file)
    define('FCPATH', str_replace(SELF, '', __FILE__));

    // Name of the "system folder"
    define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));


    // The path to the "application" folder
    if (is_dir($application_folder))
    {
        define('APPPATH', $application_folder.'/');
    }
    else
    {
        if ( ! is_dir(BASEPATH.$application_folder.'/'))
        {
            exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
        }

        define('APPPATH', BASEPATH.$application_folder.'/');
    }

require_once BASEPATH.'core/CodeIgniter'.EXT;

Kindly if you have time can u come online on skype ,
and add me khurram.shairyar.
I would be grateful
#6

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

[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>
    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} ^application.*
    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>
#8

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

[eluser]InsiteFX[/eluser]
For CI 2.0 you can leave this like so it will auto fill it in.
Code:
$config['base_url']  = '';

InsiteFX
#10

[eluser]sheri.nust[/eluser]
The problem is solved now Smile ,
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:
&lt;?

with tag
Code:
&lt;?php


And also include

Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

So my model class now is

Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Administrator_model extends  CI_Model
{
    /**
     * Enter description here...
     *
     * @return Administrator_model
     */
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    
    
    
    
}
?&gt;

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:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Enter description here...
*
* @package PointOfSale
* @since Tuesday, June 09, 2009
* @filesource
*/
class Administrator_model extends  CI_Model
{
    /**
     * Enter description here...
     *
     * @return Administrator_model
     */
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    
    
    
    
}



Is this is correct according to the convention of CI model?




Theme © iAndrew 2016 - Forum software by © MyBB