CI框架下的PHP增删改查总结

controllers下的 cquery.php文件  class CQuery extends Controller {            //构造函数      function CQuery() {          parent::Controller();  //      $this->load->database();                }        
摘要由CSDN通过智能技术生成

controllers下的 cquery.php文件

  1. <?php  
  2.   
  3. class CQuery extends Controller {  
  4.       
  5.     //构造函数  
  6.     function CQuery() {  
  7.         parent::Controller();  
  8. //      $this->load->database();  
  9.           
  10.     }  
  11.       
  12.     function index() {  
  13.         //调用model  其中train为外层文件夹   MQuery为model名称  queryList为重命名  
  14.         $this->load->model('train/MQuery','queryList');  
  15.         //获得返回的结果集   这里确定调用model中的哪个方法  
  16.         $result = $this->queryList->queryList();  
  17.         //将结果集赋给res  
  18.         $this->smarty->assign('res',$result);  
  19.         //跳转到显示页面  
  20.         $this->smarty->view('train/vquery.tpl');     
  21.     }  
  22.       
  23.     //进入新增页面  
  24.     function addPage() {  
  25.         $this->smarty->view('train/addPage.tpl');  
  26.     }  
  27.       
  28.     //新增  
  29.     function add() {  
  30.         //获得前台数据  
  31.         //用户名  
  32.         $memberName = $this->input->post('memberName');  
  33.         //密码  
  34.         $password = $this->input->post('password');  
  35.         //真实姓名  
  36.         $userRealName = $this->input->post('userRealName');  
  37.         //性别  
  38.         $sex = $this->input->post('sex');  
  39.         //出生日期  
  40.         $bornDay = $this->input->post('bornDay');  
  41.         //e_mail  
  42.         $eMail = $this->input->post('eMail');  
  43.         //密码问题  
  44.         $question = $this->input->post('question');  
  45.         //密码答案  
  46.         $answer = $this->input->post('answer');  
  47.         //调用model  
  48.         $this->load->model('train/MQuery','addRecord');  
  49.         //向model中的addRecord传值  
  50.         $result = $this->addRecord->addRecord($memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer);  
  51.         //判断返回的结果,如果返回true,则调用本页的index方法,不要写 $result == false 因为返回的值未必是false 也有可能是""   
  52.         if ($result) {  
  53.             $this->index();  
  54.         } else {  
  55.             echo "add failed.";  
  56.         }  
  57.     }  
  58.       
  59.     //删除  
  60.     function deletePage() {  
  61.         //获得ID  
  62.         $deleteID = $this->uri->segment(4);  
  63.         //调用model  
  64.         $this->load->model('train/MQuery','delRecord');  
  65.         //将值传入到model的delRecord方法中  
  66.         $result = $this->delRecord->delRecord($deleteID);  
  67.         //判断返回值  
  68.         if ($result) {  
  69.             $this
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值