[請益] CI 3.0, Unable to locate the model

看板PHP作者 (崩啾)時間10年前 (2015/07/31 12:55), 10年前編輯推噓3(308)
留言11則, 6人參與, 最新討論串1/1
各位版大好 我在設定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://www.ptt.cc/bbs/PHP/M.1438318551.A.80E.html

07/31 13:06, , 1F
$this->load->model('customermodel'); 這行跟下一行
07/31 13:06, 1F

07/31 13:07, , 2F
customermodel 改成 Customermodel 試試看
07/31 13:07, 2F

07/31 13:39, , 3F
基本上,就錯誤訊息,你的錯是在你的model,所以應該
07/31 13:39, 3F

07/31 13:39, , 4F
要改module的大小寫...
07/31 13:39, 4F

07/31 15:30, , 5F
customermodel.php 改成 Customermodel.php
07/31 15:30, 5F
謝謝,如k大所說,把檔名改大寫就可以了 印象中2.2用小寫是對的,我先來爬一下CI 3.0的changelog ※ 編輯: qm29213039 (203.75.167.229), 07/31/2015 16:15:43

08/01 19:36, , 6F
ci 3 檔名要大寫
08/01 19:36, 6F

08/01 19:38, , 7F
另外直接把值弄成 array 丟進去不久不用弄那麼多次
08/01 19:38, 7F

08/21 09:01, , 8F
CI 3 檔名要大寫, 但 $this->load->model() 這裡不用 XD
08/21 09:01, 8F

02/05 14:02, , 9F
我之前也碰到這問題但不知道為甚麼一定要改成首字母大寫
02/05 14:02, 9F

02/05 14:02, , 10F
PS. 我的 model 原始檔名是類似 AaaBbbCcc.php
02/05 14:02, 10F

02/05 14:04, , 11F
結果錯誤訊息上面的檔名是Aaabbbccc.php
02/05 14:04, 11F
文章代碼(AID): #1Lkl_NWE (PHP)
文章代碼(AID): #1Lkl_NWE (PHP)