duandi4238 2013-02-07 17:49
浏览 72
已采纳

CodeIgniter:如何从View获取输入并在控制器中使用它

I'm quite new to CodeIgniter (using PHP). So right now I have a textbox on my webpage where visitors are requested to enter in their names. I take in a name (i'll use the variable $username for it) and I want to save it in a database I have. I am wondering how I can do that. Do I somehow pass $username to a function in the Controller and then pass that value to my Model? Thank you very much, a simple example would be much appreciated!!

  • 写回答

2条回答 默认 最新

  • dongou5100 2013-02-07 21:20
    关注
    <form method="post" action="<?php echo base_url();?>controller/save" name="form">
      <label>User Name</label>
      <input type="text" name="Username">   
      <input type="submit" value="Add"/>
    </form>
    

    in controller

    function save
        {
        $arrData["Username"] = $this->input->post("Username");
        $this->User_model->Add($arrData); 
        } 
    

    in User_model

    function Add($arrData) { 
            if($this->db->insert(tableName, $arrData))
              return true;
            else
              return false;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部