php架構 - Thinkphp中D方法必須要有對應資料庫嗎?

來源:互聯網
上載者:User

之前做得一個小項目代碼

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(任何錶名)

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.