之前做得一個小項目代碼
class LoginController extends Controller { public function login(){ $Admin = D('Login'); //執行個體化Admin模型 if ($Admin->create()){ //建立資料模型 $user = I('post.name'); $this->session($user); $this->success('Login success!',"/hc_tp/Admin"); //跳轉到內頁面 }else { echo $this->error($Admin->getError()); } }}
這裡調用D方法的資料表 首碼_Login 是不存在的,
今天再重新做一個新的項目的時候提醒出現這個,提示資料表不存在
求解,忘了當時是搞了TP得配置還是怎麼的
回複內容:
之前做得一個小項目代碼
class LoginController extends Controller { public function login(){ $Admin = D('Login'); //執行個體化Admin模型 if ($Admin->create()){ //建立資料模型 $user = I('post.name'); $this->session($user); $this->success('Login success!',"/hc_tp/Admin"); //跳轉到內頁面 }else { echo $this->error($Admin->getError()); } }}
這裡調用D方法的資料表 首碼_Login 是不存在的,
今天再重新做一個新的項目的時候提醒出現這個,提示資料表不存在
求解,忘了當時是搞了TP得配置還是怎麼的
模型對對應的資料表 預設是跟模型名同名的資料表
Login模型預設對應Login表,
如果不想這樣對應,可以用
protected $tableName='tablename';
指定資料表名
think PHP裡模型的名字必須是表名
D方法內部實現是執行個體化具體的資料表類
可以設定虛擬模型
class LoginModel extends Model { protected $autoCkeckFields = false; //關閉檢測欄位}
不一定! 應該是D(ModelName); 預設ModelName 對應的是表名,不對應的話會報錯, 但是可以通過
protected $autocheckfields = false; 來關閉自動對應, 這樣你在Model裡就可以 隨便M(任何錶名)