Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

CodeIgniter PHP Model Access "Unable to locate the model you have specified"

I have been trying to load some models for this website I am building. However, for an unknown reason, it will bring the following error :

An Error Was Encountered

Unable to locate the model you have specified: logon_model

Now , I have done my research. The problem would be that IC processes file names in lowercase. However, both my file and the file calling is in lower case, as shown here :

echo "VALIDATING";
            // Validation passed. Off we go to account info verification from AA's database. God help us all.
            $this->load->model('logon_model');
            echo "FOUND MODEL";
            $res = $this->logon_model->verify_user($this->input->post('username'),$this->input->post('password'));
            echo $this->input->post('username');
            echo $this->input->post('password');

The execution does not reach "FOUND MODEL", thus stops on the model loading. I have tried to use:

 $this->load->model(site_url('logon_model'));

With no results. Need to mention the model file is correctly placed in the right model folder ?

How can I fix this ?

EDIT : Header for the model file :

class Logon_model extends CI_Model {

....
question from:https://stackoverflow.com/questions/8074368/codeigniter-php-model-access-unable-to-locate-the-model-you-have-specified

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When creating models, you need to place the file in application/models/ and name the file in all lowercase - like logon_model.php

The logon_model.php should contain the following:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Logon_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    ...

Now, what you can do, to test if your application model is reachable, is to try opening it in the browser - like so:
http://example.org/application/models/logon_model.php

If you see the text No direct script access allowed it means you hit the right file (if you are in doubt, try writing something else in the exit() in the first line).

Secondly, for loading the model in your controllers, you should be able to do like this:

public function index()
{

    $this->load->model('logon_model');
    ...

}

If everything above checks out as expected I would begin looking at file permissions and/or possibly symlinks if you are using any.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...