jQuery MiniUI

 找回密码
 立即注册
查看: 8196|回复: 8
打印 上一主题 下一主题

哪位高手给出Thinkphp和miniui表单提交和查询的例子 [复制链接]

Rank: 1

跳转到指定楼层
楼主
发表于 2012-10-9 09:47:56 |只看该作者 |倒序浏览
哪位高手给出Thinkphp和miniui表单提交和查询的例子,感谢!

Rank: 9Rank: 9Rank: 9

沙发
发表于 2012-10-9 09:59:35 |只看该作者
先用Thinkphp实现普通的ajax和Json交互的示例。
比如你自己找一个jquery的ajax加载thinkphp的文章等。
然后用miniui的url指向此地址即可。

Rank: 1

板凳
发表于 2012-10-9 10:07:19 |只看该作者
能给出详细的示例吗?谢谢!

Rank: 1

地板
发表于 2012-10-9 10:16:36 |只看该作者
初次接触jquery和Thinkphp , 心血来潮就结合这两个做了个登陆的例子 :
  
页面代码:

<div align="center">
   <p>用户名:
     <input type="text" name="lid" id="lid" />
   </p>
   <p>密码:
   <input type="text" name="pwd" id="pwd" />
   </p>  
   <p>
     <input type="submit" name="loginbt" id="loginbt" value="登 陆" />
   </p>
   <p><div id="state" name="state"></div></p>
</div>



Javascript代码有两种方法)


    $(document).ready(function(){
         $('#loginbt').click(function(){
             // case one :
             $.ajax({
                 type:"OST",
                 url:"../index.php/index/doAjax",
                 data:{lid('#lid').val(),pwd('#pwd').val()},
                 success:function(msg){
                             $('#state').html(msg);
                         }           
             });   
             // case two:
             /*
             $.post("../index.php/index/doAjax",{lid('#lid').val(),pwd('#pwd').val()},function(msg){
                 $('#state').html(msg);
             });
             */
         });
     });




后台php代码:



class IndexAction extends Action
{
     public function index()
     {

    }
     
     public function doAjax()
     {
         $lid=$_POST["lid"];
         $pwd=$_POST["pwd"];
         if($lid==""||$pwd=="")
                 echo '用户名或密码为空!';
         else
         {
             if($lid=="admin" && $pwd=="admin")
                     echo '登陆成功!';
             else
                     echo '登陆失败!';
         }
     }
}

Rank: 1

5#
发表于 2012-10-9 10:18:54 |只看该作者
0938cs 发表于 2012-10-9 10:16
初次接触jquery和Thinkphp , 心血来潮就结合这两个做了个登陆的例子 :
  
页面代码:

请管理员看是否正确?

Rank: 1

6#
发表于 2012-10-9 10:23:11 |只看该作者
网官方多给出Thinkphp和miniui例子一并放到论坛或下载!

Rank: 8Rank: 8

7#
发表于 2012-10-9 10:43:29 |只看该作者
0938cs 发表于 2012-10-9 10:23
网官方多给出Thinkphp和miniui例子一并放到论坛或下载!

你只需要前台获取到miniui控件的值,其他的只需要正常使用ajax提交到后台进行判断即可了
请参考MINIUI对应控件的API,上面有各种属性方法事件的

Rank: 2

8#
发表于 2012-10-9 16:32:07 |只看该作者
很简单啊

提交数据
miniui代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.     <title>{$Think.config.site_name}</title>
  5.     <meta http-equiv="content-type" content="text/html; charset=UTF-8" />

  6.     <css href="__PUBLIC__/Css/main.css" />
  7.     <js href="__PUBLIC__/Js/boot.js"/>

  8. </head>
  9. <body>
  10.     <form id="form1" method="post">
  11.         <input name="department_id" class="mini-hidden" value="{$Dept.dept_id}"/>
  12.         <div style="padding-left:11px;padding-bottom:5px; padding-top: 10px; padding-right: 10px;">
  13.             <table style="table-layout:fixed;" cellspacing="5">
  14.                 <tr>
  15.                     <td style="width:70px;">部门名称:</td>
  16.                     <td style="width:150px;">   
  17.                         <input name="dept_name" class="mini-textbox" required="true" value="{$Dept.dept_name}"/>
  18.                     </td>
  19.                 </tr>
  20.                 <tr>
  21.                     <td >部门描述:</td>
  22.                     <td >
  23.                         <input name="dept_desc" class="mini-textarea" style="width:350px; height: 80px;" value="{$Dept.dept_desc}"/>
  24.                     </td>
  25.                 </tr>
  26.             </table>
  27.         </div>

  28.         <div style="text-align:center;padding:10px;">               
  29.             <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>      
  30.             <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>      
  31.         </div>        
  32.     </form>

  33.     <script type="text/javascript">
  34.         mini.parse();
  35.         var form = new mini.Form("form1");
  36.         function SaveData() {
  37.             var o = form.getData();
  38.             form.validate();
  39.             if (form.isValid() == false) return;
  40.             $.ajax({
  41.                 type:"post",
  42.                 url: "__APP__/Department/updateDepartment",
  43.                 data: o,
  44.                 cache: false,
  45.                 success: function (text) {
  46.                     CloseWindow("save");
  47.                 },
  48.                 error: function (jqXHR, textStatus, errorThrown) {
  49.                     alert(jqXHR.responseText);
  50.                     CloseWindow();
  51.                 }
  52.             });
  53.         }
  54.     </script>
  55. </body>
  56. </html>
复制代码
Thinkphp代码
  1. public function updateDepartment() {
  2.         if($_REQUEST['department_id']){
  3.             $data['dept_name'] = $_REQUEST['dept_name'];
  4.             $data['dept_desc'] = $_REQUEST['dept_desc'];

  5.             $Depts = D('Dept');
  6.             $vo= $Depts->where('dept_id = ' .$_REQUEST['department_id'])->save($data);
  7.             if($vo){
  8.                 $this->ajaxReturn($vo,'部门信息已更新!)',1);
  9.             }else{
  10.                 $this->ajaxReturn(0,'部门信息更新失败!',0);
  11.             }
  12.         }
  13.     }
复制代码

Rank: 2

9#
发表于 2012-10-9 16:35:42 |只看该作者
查询就更简单了
thinkphp查询的结果数组转成json返回就可以了
  1. //读取部门列表
  2.     public function GetDepartmentList() {
  3.         $Depts = D('Department');
  4.         $DeptL1 = $Depts->order('id asc')->select();
  5.         $s = json_encode($DeptL1);
  6.         echo $s;
  7.     }
复制代码

Archiver|普加软件

GMT+8, 2024-7-3 18:18 , Processed in 1.022894 second(s), 10 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部