作者qm29213039 (崩啾)
看板PHP
标题[请益] CI 3.0, Unable to locate the model
时间Fri Jul 31 12:55:45 2015
各位版大好
我在设定db连接的时候遇到下列的错误讯息
Unable to locate the model you have specified: Customermodel
照着google找到的讯息,大概都是说我大小写设定好就可以解决了
可是照着做还是喷错,想请益一下可能还有哪边没有设定好?
以下是程式码:
controller/Login.php
<?PHP
if ( !defined('BASEPATH')) OR exit('No direct script access allowed');
class Login extends CI_Controller{
puclic funtion save(){
$this->load->model('customermodel');
$this->customermodel->insert($firstName, $lastName);
}
}
models/customermodel.php
<?PHP
if( !defined('BASEPATH')) OR exit('No direct scirpt access allowed');
class Customermodel extends CI_Model{
public funtion __construct()
{
parent::__construct();
}
function insert($firstName, $lastName){
$this->db->insert('customer_data',
Array("firstName" => $firstName,
"lastName" => $lastName
));
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 203.75.167.229
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/PHP/M.1438318551.A.80E.html
1F:→ itisjoe: $this->load->model('customermodel'); 这行跟下一行 07/31 13:06
2F:→ itisjoe: customermodel 改成 Customermodel 试试看 07/31 13:07
3F:→ chenxiaowoo: 基本上,就错误讯息,你的错是在你的model,所以应该 07/31 13:39
4F:→ chenxiaowoo: 要改module的大小写... 07/31 13:39
5F:推 Kenqr: customermodel.php 改成 Customermodel.php 07/31 15:30
谢谢,如k大所说,把档名改大写就可以了
印象中2.2用小写是对的,我先来爬一下CI 3.0的changelog
※ 编辑: qm29213039 (203.75.167.229), 07/31/2015 16:15:43
6F:→ chan15: ci 3 档名要大写 08/01 19:36
7F:→ chan15: 另外直接把值弄成 array 丢进去不久不用弄那麽多次 08/01 19:38
8F:推 hit1205: CI 3 档名要大写, 但 $this->load->model() 这里不用 XD 08/21 09:01
9F:推 pizzahut: 我之前也碰到这问题但不知道为甚麽一定要改成首字母大写 02/05 14:02
10F:→ pizzahut: PS. 我的 model 原始档名是类似 AaaBbbCcc.php 02/05 14:02
11F:→ pizzahut: 结果错误讯息上面的档名是Aaabbbccc.php 02/05 14:04