作者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/m.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