/* 取得列表数据 */
$model_wish =& m('wish');
$wish= $model_wish->find(array(
'conditions' => 'user_id = ' . $this->visitor->get('user_id'),//这里是查询条件
));
$this->assign('wishlist', $wish);
弹出对话框时:
<b class="ico1" ectype="dialog" dialog_title="{$lang.wish_create}" dialog_id="wish_add" dialog_width="600" uri="index.php?app=wish&act=add">弹窗</b>
dialog_id必须是当前弹窗的app_act,否则会和后台的app_act不对应,导致弹窗无法关闭。
获取用户sessionid:$this->visitor->get('user_id') $_SESSION['user_info']['user_id']
<?php
$options = array('equal'=>'ccc');
!isset($options['equal']) && $options['equal'] = '=';
echo $options['equal']
?>
代码含义是如果options数组中定义了某个键,那么就显示这个定义的,如果没定义,或为空,那么会自动赋值=号。
会员中心添加、修改、删除代码
1 function add() 2 { 3 if (!IS_POST) 4 { 5 /* 当前位置 */ 6 /*$this->_curlocal(LANG::get('member_center'), 'index.php?app=member', 7 LANG::get('my_address'), 'index.php?app=my_address', 8 LANG::get('add_address'));*/ 9 //$this->import_resource('mlselection.js, jquery.plugins/jquery.validate.js'); 10 $this->assign('act', 'add'); 11 header('Content-Type:text/html;charset=' . CHARSET); 12 $this->display('wish.form.html'); 13 } 14 else 15 { 16 /* 心愿名称必填 */ 17 if (!$_POST['wish_title']) 18 { 19 $this->pop_warning('wishtitle_required'); 20 return; 21 } 22 23 $data = array( 24 'user_id' => $this->visitor->get('user_id'), 25 'wish_title'=> $_POST['wish_title'], 26 'way' => $_POST['way'], 27 'ctime' => strtotime(date('Y-m-d H:i:s'))-date("Z"), 28 'isdefault' => $_POST['default'], 29 'namee' => $_POST['names'], 30 'email' => $_POST['email'], 31 'sr' => $_POST['sr'], 32 'mycont' => $_POST['mycont'], 33 'myset' => $_POST['myset'], 34 ); 35 $model_wish =& m('wish'); 36 if (!($wishid = $model_wish->add($data))) 37 { 38 $this->pop_warning($model_wish->get_error()); 39 return; 40 } 41 $this->pop_warning('ok'); 42 } 43 } 44 function edit() 45 { 46 $id = empty($_GET['wishid']) ? 0 : intval($_GET['wishid']); 47 if (!$id) 48 { 49 echo Lang::get("no_such_wish"); 50 return; 51 } 52 if (!IS_POST) 53 { 54 $model_address =& m('wish'); 55 $find_data = $model_address->find("wishid = {$id} AND user_id=" . $this->visitor->get('user_id')); 56 if (empty($find_data)) 57 { 58 echo Lang::get('no_such_wish'); 59 60 return; 61 } 62 $address = current($find_data); 63 64 /* 当前位置 */ 65 $this->_curlocal(LANG::get('member_center'), 'index.php?app=member', 66 LANG::get('my_address'), 'index.php?app=my_address', 67 LANG::get('edit_address')); 68 69 70 $this->assign('act', 'edit'); 71 $this->assign('wish', $address); 72 //$this->import_resource('mlselection.js, jquery.plugins/jquery.validate.js'); 73 $this->assign('act', 'edit'); 74 header('Content-Type:text/html;charset=' . CHARSET); 75 $this->display('wish.form.html'); 76 } 77 else 78 { 79 /* 电话和手机至少填一项 */ 80 if (!$_POST['wish_title']) 81 { 82 $this->pop_warning('wishtitle_required'); 83 84 return; 85 } 86 $data = array( 87 'user_id' => $this->visitor->get('user_id'), 88 'wish_title'=> $_POST['wish_title'], 89 'way' => $_POST['way'], 90 'isdefault' => $_POST['default'], 91 'namee' => $_POST['names'], 92 'email' => $_POST['email'], 93 'sr' => $_POST['sr'], 94 'mycont' => $_POST['mycont'], 95 'myset' => $_POST['myset'], 96 ); 97 $model_address =& m('wish'); 98 $model_address->edit("wishid = {$id} AND user_id=" . $this->visitor->get('user_id'), $data); 99 if ($model_address->has_error()) 100 { 101 $this->pop_warning($model_address->get_error()); 102 103 return; 104 } 105 $this->pop_warning('ok', APP.'_'.ACT); 106 } 107 } 108 function drop() 109 { 110 $id = isset($_GET['id']) ? trim($_GET['id']) : 0; 111 if (!$id) 112 { 113 $this->show_warning('no_such_address'); 114 115 return; 116 } 117 $ids = explode(',', $id);//获取一个类似array(1, 2, 3)的数组 118 $model_wish =& m('wish'); 119 $drop_count = $model_wish->drop("wishid = " . $_GET['id'] . ""); 120 if (!$drop_count) 121 { 122 /* 没有可删除的项 */ 123 $this->show_warning('no_such_address'); 124 125 return; 126 } 127 128 if ($model_wish->has_error()) //出错了 129 { 130 $this->show_warning($model_address->get_error()); 131 132 return; 133 } 134 135 $this->show_message('drop_wish_successed'); 136 }
输出日期:
{$rows.time|date:Y-m-d H:i:s}
$_SERVER['argv'][0]和$_SERVER['QUERY_STRING']一样 获取get参数,第一个返回数组且只有1维就包括全部参数,后者返回是字符串
$_SERVER['REQUEST_URI'] 返回 /和当前文件全称及参数,如:http://localhost/cs3.php?a=1&b=2 返回 /cs3.php?a=1&b=2
$_SERVER['PHP_SELF'] 和 $_SERVER['SCRIPT_NAME'] 返回结果一样都是文件名称不带参数 如:/cs3.php