HTML5¼¼Êõ

thinkphpÐÅÏ¢Ð޸ĺͷÖÒ³ - µÏ¶÷½Ü

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-12-20 16:06 ÎÒÒªÆÀÂÛ( )

¹ØÁªÁ½¸öÊý¾Ý±í£¬ÔÚModelÀィÁ¢StuModel.class.php: ?php//Belongs_to ¹ØÁª±íʾµ±Ç°Ä£ÐÍ´ÓÊôÓÚÁíÍâÒ»¸ö¸¸¶ÔÏónamespace Admin\Model;use Think\Model\RelationModel;class StuModel extends RelationModel{protected $_link = array('Clas' = array('mapping

¹ØÁªÁ½¸öÊý¾Ý±í£¬ÔÚModelÀィÁ¢StuModel.class.php:

<?php //Belongs_to ¹ØÁª±íʾµ±Ç°Ä£ÐÍ´ÓÊôÓÚÁíÍâÒ»¸ö¸¸¶ÔÏó namespace Admin\Model; use Think\Model\RelationModel; class StuModel extends RelationModel { protected $_link = array( 'Clas' => array( 'mapping_type' => self::BELONGS_TO, 'class_name' => 'Clas', 'foreign_key' => 'clas_id', // 'mapping_name' => 'dept', ), ); }

¡¡¡¡

 

ÔÚviewÖн¨Á¢StuÎļþ¼Ð£¬½¨Á¢Ö÷Ò³Ãæindex.html£º

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <table> <tr> <td>Ãû×Ö</td> <td>ÐÔ±ð</td> <td>ÉúÈÕ</td> <td>°à¼¶</td> <td>ÐÞ¸Ä</td> </tr> <volist> <tr> <td> {$vo.uname} </td> <td> <if condition="$vo.sex eq 1"> ÄÐ <else/> Å® </if> </td> <td> {$vo.birthday} </td> <td> {$vo.Clas.cname} </td> <td><a href="{:U('Stu/editShow',array('id'=>$vo[id]))}">±à¼­</a></td> </tr> </volist> </table> <hr> <table> <tr> <td>Ãû×Ö</td> <td>ÐÔ±ð</td> <td>ÉúÈÕ</td> <td>°à¼¶</td> <td>ÐÞ¸Ä</td> </tr> <tbody> </tbody> </table> <input type="hidden" value="1"> <input type="submit" value="ÉÏÒ»Ò³"> <input type="submit" value="ÏÂÒ»Ò³"> <script src="__JS__/jquery-2.2.3.min.js"></script> <script> function dataGet(pag_num,count) { //ajax $.ajax({ url:'{:U("Stu/ajaxSelect")}', dataType:'json', type:'post', data:{ pag_num:pag_num, count:count }, success:function (data) { var str=''; for (var i in data){ if (data[i].sex == 1){ data[i].sex = 'ÄÐ'; }else{ data[i].sex = 'Å®'; } str += '<tr>' + ' <td>' + data[i].uname + ' </td>' + ' <td>' + data[i].sex + ' </td>' + ' <td>' + data[i].birthday.substr(0,10) + ' </td>' + ' <td>' + data[i].Clas.cname + ' </td>' + ' <td><a href="{:U("Stu/editShow")}?id=' + data[i].id + '">±à¼­</a>' + '</td>' + '</tr>' } $('#data').html(str); $('#page').val(pag_num); } }) }
//Êý¾ÝÏÔʾÊýÁ¿ dataGet(1,1);
//µã»÷Çл» $('#prev').click(function () { var page = parseInt($('#page').val()) dataGet(page-1,1); }); $('#next').click(function () { var page = parseInt($('#page').val()) dataGet(page+1,1); }) </script> </body> </html>

¡¡¡¡ÔÚStuÖн¨Á¢ÐÞ¸ÄÒ³Ãæedit.html£º

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <table> <tr> <td>Ãû×Ö</td> <td>ÐÔ±ð</td> <td>ÉúÈÕ</td> <td>°à¼¶</td> <td>ÐÞ¸Ä</td> </tr> <form action="{:U('Stu/editPost')}" method="post"> <tr> <td><input type="text" value="{$stu.uname}"></td> <td> <if condition="$stu['sex'] eq 1"> <input type="radio" value="1" checked><labl for="man">ÄÐ</labl> <input type="radio" value="0"><labl for="woman">Å®</labl> <else/> <input type="radio" value="1"><labl for="man">ÄÐ</labl> <input type="radio" value="0" checked><labl for="woman">Å®</labl> </if> </td> <td><input type="text" value="{$stu.birthday}"></td> <td> <select> <option value="">Ñ¡Ôñ°à¼¶</option> <volist> <if condition="$stu['clas_id'] eq $vo['id']"> <option value="{$vo.id}" selected>{$vo.cname}</option> <else/> <option value="{$vo.id}">{$vo.cname}</option> </if> </volist> </select> </td> <td> <input type="hidden" value="{$stu.id}"> <input type="submit" value="Ìá½»"> </td> </tr> </form> </table> </body> </html>

¡¡¡¡ÔÚControllerÖн¨Á¢StuController.class.php£º

<?php namespace Admin\Controller; use Think\Controller; class StuController extends Controller { public function index(){ $db_stu = D('Stu'); $data_stu = $db_stu->relation(true)->select(); // dump($data_stu); $this->assign('Stu',$data_stu); $this->display(); } public function ajaxSelect(){ $pag = I('post.pag_num'); $count = I('post.count'); $db_stu = D('stu'); $data_stu = $db_stu->relation(true)->page($pag,$count)->select(); $this->ajaxReturn($data_stu); } public function editShow(){ if (IS_GET){ $id = I('get.id'); // dump($id); $db_stu = M('Stu'); $db_clas = M('Clas'); $data_stu = $db_stu->where('id = '.$id)->find(); $data_clas = $db_clas->where('status = 1')->select(); $this->assign('clas',$data_clas); $this->assign('stu',$data_stu); $this->display('Stu/edit'); } } public function editPost(){ if (IS_POST){ $data = I('post.'); // dump($data); $db_stu = M('stu'); $db_stu->save($data); // dump($m); $this->success('³É¹¦','index'); } } }

¡¡¡¡

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • ʵÏÖÊäÈë¿ò¡¾ÊäÈëÌîд+¶¯Ì¬ÌáʾÐÅÏ¢+ÏÂÀ­Ñ¡Ôñ¡¿ - ¾Æ²»×íÐÄ

    ʵÏÖÊäÈë¿ò¡¾ÊäÈëÌîд+¶¯Ì¬ÌáʾÐÅÏ¢+ÏÂÀ­Ñ¡Ôñ¡¿ - ¾Æ²»×íÐÄ

    2017-10-30 18:01

  • ±àдServlet£¬ÑéÖ¤Óû§µÇ¼£¬Èç¹ûÓû§ÃûÓëÃÜÂ붼Ϊ¡°admin¡±ÔòÑé֤ͨ¹ý£¬Ìøת»¶Ó­Ò³Ã棬·ñÔòµ¯³öÌáʾÐÅÏ¢¡°Óû§Ãû»ò

    ±àдServlet£¬ÑéÖ¤Óû§µÇ¼£¬Èç¹ûÓû§ÃûÓëÃÜÂ붼Ϊ¡°admin¡±ÔòÑé֤ͨ

    2017-09-14 16:09

  • ±¾µØ´æ´¢ÓëµØÀíÐÅÏ¢ - ×óתÓÒת

    ±¾µØ´æ´¢ÓëµØÀíÐÅÏ¢ - ×óתÓÒת

    2017-08-17 16:01

  • ±¾µØÐÞ¸Äjs´úÂ벢ʱʱÉúЧµÄ½â¾ö°ì·¨ - µÈÄã¹éÈ¥À´

    ±¾µØÐÞ¸Äjs´úÂ벢ʱʱÉúЧµÄ½â¾ö°ì·¨ - µÈÄã¹éÈ¥À´

    2017-06-09 14:00

ÍøÓѵãÆÀ
Œ