午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    模型model-ci(codeigniter)php框架
    來源:易賢網(wǎng) 閱讀:800 次 日期:2014-10-24 13:58:44
    溫馨提示:易賢網(wǎng)小編為您整理了“模型model-ci(codeigniter)php框架”,方便廣大網(wǎng)友查閱!

    開始對codeigniter礦建模型mode的學習,模型在mvc框架里面主要內(nèi)容是與數(shù)據(jù)庫的交互,包括數(shù)據(jù)庫的讀寫等。

    在ci中模型很簡單,模型的位置在application/models路徑下面。

    下面定義一個新聞類,包括讀read 寫write 改change 刪除

    按照一個新聞類來說,定義一個新聞模型 為news.php代碼為

    class news extend ci_model{

    function __construct(){

    parent::__construct();

    }

    function read($id){

    $query = $this->db->get('newstable',$id);

    return $query;//這里返回的是一個數(shù)組,可以通過$query['id'],$query['title']//進行訪問

    }

    function write(){

    $this->title = $post['title'];//獲取提交過來的新聞title

    $this->content = $this->input->post('content');//獲取提交過來的內(nèi)容,推薦這種方法

    $this->db->insert('newstable',$this);

    return $this->db->affected_rows();//返回影響行數(shù),如果有自動增長字段,則返回新的增長id

    }

    function change($id){

    $this->title = $post['title'];//獲取提交過來的新聞title

    $this->content = $this->input->post('content');//獲取提交過來的內(nèi)容,推薦這種方法

    $this->db->update('newstables',$this,array('id'=>$id));//這里的id可以提交過來也可以,post過來

    return $this->db->affected_rows();//返回一想行數(shù)

    }

    function delete($id){//刪除對應(yīng)id信息

    $this->db->where('id',$id);

    $this->db->delete('newstable');

    }

    }

    //調(diào)用模型model 在控制其中執(zhí)行,

    <?php

    class pages extends ci_controller {

    function __construct() {

    parent::__construct();

    }

    public function read($id) {

    $this->load->model(news);//調(diào)用news模型

    $data = $this->news->read($id);//調(diào)用模型read方法,參數(shù)為$id

    $this->load->view('pages',$data);//調(diào)用視圖pages,并傳遞參數(shù)為返回來的新聞$data

    }

    }

    ?>

    //調(diào)用模型實際方法為

    $this->load->model('model_name');

    $this->model_name->function();

    可以對對象起別名

    $this->load->model('model_name', 'newmodel_name');

    $this->newmodel_name->function();

    以上就是模型調(diào)用,還是比較容易理解的。

    更多信息請查看IT技術(shù)專欄

    更多信息請查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機網(wǎng)站地址:模型model-ci(codeigniter)php框架

    2025國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)