thinkPHP -- 使用者名稱驗證、資料分頁

來源:互聯網
上載者:User

標籤:輸入框   play   資料集   isp   box   提示資訊   物件類型   util   this   

使用者名稱驗證:  用Ajax 和 jshtml中 Ajax 將輸入框中的值 傳入PHP檔案, 和資料庫中的值進行匹配,用Ajax的回調將結果回調到html檔案中,html再用js改變提示資訊//blur滑鼠離開時的方法jq方法//jq擷取使用者名稱輸入框的標籤$(‘#name‘).blur() html檔案中擷取input內容$(this).attr(‘value’); // 擷取某個元素的屬性值  頭尾分離文檔:8.7包含檔案<include file="header" /> <!— <include file=“Public:header”/>  不常用-->$this->display(‘Public:footer‘);              Tpl下的檔案  檔案中的內容常用的是:public function view($nameFun){
    $this->display(‘Public:header‘);
    $this->display($nameFun);
    $this->display(‘Public:footer‘);} 迴圈標籤 <foreach></foreach> <foreach name="result" item="val">(迴圈體)</foreach> 標籤賦值{$_SESSION.admin.name}相當於—  <?php echo $?_SESSION.admin.name>重新導向// 重新導向 在user控制器用product控制器的index方法
$this->redirect(‘product/index‘);擷取資料//        $model = M(‘Product‘);//        $result = $model->select();//        // 傳值給模板頁面//        $this->assign(‘result‘,$result);  資料分頁  $model = M(‘Product‘); // 執行個體化User對象 //        import(‘ORG.Util.Page‘);// 匯入分頁類         $count = $model->count();// 查詢滿足要求的總記錄數         $Page  = new Page($count,2);// 執行個體化分頁類 傳入總記錄數和每頁顯示的記錄數         $show  = $Page->show();// 分頁顯示輸出         // 進行分頁資料查詢 注意limit方法的參數要使用Page類的屬性         $list = $model->order(‘id desc‘)->limit($Page->firstRow.‘,‘.$Page->listRows)->select();         $this->assign(‘result‘,$list);// 賦值資料集         $this->assign(‘page‘,$show);// 賦值分頁輸出         $this->view(); // 輸出模板 最佳化後:// 第一步: 匯入三方庫        // // 支援Ajax的分頁功能
        import("ORG.Util.AjaxPage");
        $model = M(‘Product‘); // 執行個體化Product對象// 第二步: 建立對象, 指定對象執行的方法        $count = $model->count();// 查詢滿足要求的總記錄數
        $Page  = new AjaxPage($count,2, "productPage");// productPage 是調用js中方法, 通過該方法給js傳遞頁碼值
        $show  = $Page->show();// 分頁顯示輸出
        // 進行分頁資料查詢 注意limit方法的參數要使用Page類的屬性        $list = $model->order(‘id desc‘)->limit($Page->firstRow.‘,‘.$Page->listRows)->select();// 第三步: 判斷是不是Ajax        if (!$this->isAjax()){
            $this->assign(‘result‘,$list);// 賦值資料集
            $this->assign(‘page‘,$show);// 賦值分頁輸出
            $this->view(‘index‘); // 輸出模板
        }else{
            $data[‘result‘]=$list;
            $data[‘page‘]=$show;
            // 返回給Ajax
            $this->ajaxReturn($data);
        }局部重新整理需要用到Ajax<script>  function productPage(id) {     // 拼接url         控制器/方法 / 參數/參數值           var url = ‘__APP__/product/index/p/‘+id;
    $.get(url, function (content) {
      // 重寫html代碼
      // pagination div重寫
      // 將json轉成物件類型
      var data = eval(‘(‘+content+‘)‘); // 強制將json轉成物件類型      $(‘.pagination‘).html(data.page);      var l =  ‘‘; // l拼接的局部重新整理部分標籤的字串      for (var i=0;i < 2;i++) {
        l += ‘<tr><td><input type="checkbox"/></td>‘;
        l += ‘<td>‘+data.result[i][‘id‘]+‘</td>‘;
        l += ‘ <td><a href="#" title="title">‘+data.result[i][‘name‘]+‘</a></td>‘;
        l += ‘<td>‘+data.result[i][‘price‘]+‘</td>‘;
        l += ‘<td>‘+data.result[i][‘count‘]+‘</td>‘;
        l += ‘<td><a href="__APP__/product/updata/id/‘;
        l += data.result[i][‘id‘];
        l += ‘" title="Edit"><img src="__ROOT__/__PUBLIC__/resources/images/icons/pencil.png" alt="Edit" /></a>‘;
        l += ‘<a href="__APP__/product/delete/id/‘;
        l += data.result[i][‘id‘];
        l += ‘" title="Delete"><img src="__ROOT__/__PUBLIC__/resources/images/icons/cross.png" alt="Delete" /></a>‘;
        l += ‘<a href="__APP__/product/addFun" title="Edit Meta"><img src="__ROOT__/__PUBLIC__/resources/images/icons/hammer_screwdriver.png" alt="Edit Meta"/></a></td></tr>‘;
        alert(l);
        $(‘#tbodyn‘).html(l);
    }
    });  }</script>

thinkPHP -- 使用者名稱驗證、資料分頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.