文章浏览 复制本页面地址

TP使用的一点小感悟分享

一、AJAX回调div设置

[code type="css"]#tailresult{border:1px solid #d4d4d4; background:#FFC; padding:8px 70px; margin:2px 15px; line-height:185%; color:red; font-weight:bold;float:right;position:absolute;right:100px;display:none;}[/code]

<div id="tailresult" style="font-family:微软雅黑,Tahoma;letter-spacing:2px"></div>

二、AJAX的写法

[code type="javascript"]

[/code]
PHP 页面:

[code]
public function del_stu_think(){
$id = $_REQUEST['id'];
$think = M("thinking");
if(!empty($id)){
if($think->where("id='$id'")->delete()){
$this->ajaxReturn($id,'删除成功',1); #第一个值为 data 第二个为 返回显示提示信息 第三个为状态
}else{
$this->ajaxReturn($id,'删除失败',0);
}
}
}
[/code]

页面返回html中使用 $ 操作 借用原来的 jquery 里面的元素 不需要 加 #号
例如:
$('list').remove();
获取控件值:
var start_time = $("b_date").value;

+++++++++++++++++++++JESON AJAX 访问+++++++++++++++++++++++++++++++
[code]
//打开弹出窗口
function class_demo(scid,stuid,ordid,sta_date,end_date,stet){

j.getJSON("/index.php/Course/ajax_classinfo/scid/"+scid+"/stuid/"+stuid+"/ordid/"+ordid+"/sta_date/"+sta_date+"/end_date/"+end_date,function(data){
document.getElementById("show_data").innerHTML = data;
var offsetTop = j(window).scrollTop() + 80 +"px";
if(stet==1){
j("#show_software").show();
}
j("#show_teacher_result").css("top",offsetTop);
j("#show_teacher_result").fadeIn(300);
});

}

PHP

function ajax_classinfo(){

$arr = $index->where($where)->select();

$str = $arr['list']['lsc_title']."

";
$str .= '老师:'.$arr['list']['teachername']."

";
$str .= "".date("H:i",$arr['list']['bgtime'])."--".date("H:i",$arr['list']['endtime'])."

";
$str .= $arr['list']['lsc_classcon']."

";
if($arr['list']['lws_id']==''){
$str .= "
";
}
$tutor = json_encode($str);
echo $tutor;
}

[/code]

<include file="../Public/_header" /> 包含

<label><input name="sex" type="radio" value="1" <eq name="sex" value="1">checked</eq>>男</label>
<label><input name="sex" type="radio" value="0" <neq name="sex" value="1">checked</neq>>女</label>

三、标签里面直接加PHP的写法:

用户组:
if($type=='add'){ {:W('SelectUserGroup')}

}else { {:W('SelectUserGroup', array('uid'=>$uid))}

}

四、指定提交路径

W 快速Widget输出方法 小工具模块;挂件(工资计算,选外教,课时计算工具,用户权限)

**************************邮箱验证防止重复插入*******************************

五、灵感小总结

在插入信息前,一定要验证邮箱是否存在 防止插入重复

/**
* 检查Email是否可用
*
* @return boolean
*/
function isEmailAvailable($email,$uid=false) {
return D('User', 'home')->isEmailAvailable($email,$uid);
}

*************************分页模型所在**************************************

/core/sociax/Model.class.php findpage

************************************************************************

*************************分页模型所在**************************************

六、特效功能分析

Jquery 弹出当前层 并引用iframe 包含过来
通过以上去找 /public/js/tbox/box.js load 方法 把参数传给 init 方法 把内容页面 赋值给 ifrma
[code]
JS写法:
//编辑地区
function edit(area_id) {
ui.box.load("{:U('admin/Tool/editArea')}&area_id="+area_id, {title:'编辑地区'});
}
PHP写法:
public function editArea() {
$_GET['area_id'] = intval($_GET['area_id']);
$area = M('area')->where('area_id='.$_GET['area_id'])->find();
$area['area_id'] = $_GET['area_id'];
$this->assign('area', $area);
$this->display(); //这里把映射的 editArea.html 赋给了---ifram框架
}
[/code]
在页面上显示回显的浮动页面,好爽的想法,也写法啊。

再一个例子:

//弹出创建专辑窗口
[code]
function create_album_tab(uid){
ui.box.load(U('photo/Manage/create_album_tab')+'&uid='+uid,{title:'创建'+APP_NAME});
}
[/code]
************************获取配置参数****************************************

在系统中 项目中有 Common 此文件夹内 可以写公共方法; 而且可以直接使用

例如: 在 action 中可以 $aa = aaa(); // aaa() 方法是 Common 中文件里面的方法

***********************AJAX+异步页面json信息+JS 处理************************
[code]
AJAX:

$.post(U('photo/Manage/do_create_album'),{name:name,privacy:privacy,privacy_data:password},function(data){
if(data == -1){
ui.error('该相册名已存在!');
}else if(data){
parent.setAlbumOption(data)
ui.box.close();
ui.success('创建成功!');
}else{
ui.box.close();
ui.error('创建失败!');
}
});

PHP页面:

echo json_encode(array('albumId'=>$result,'albumName'=>$name));

成功JS页面:

function setAlbumOption(data){
var obj = eval('(' + data + ')'); //把返会json 解码成数组
$('#albumlist').append('

');
}

[/code]
************************获取配置参数****************************************

七、缓存的写法分析

************************快速缓存开始****************************************
[code]
function index(){
$arr = $this->getinfoF();

//$aa = F('_rules',NULL);
$aa = $this->getinfoF(); //手动删除缓存
$bb = $this->getinfoS('94');//自动删除缓存可以设置时间
dump($bb);

$this->assign('Author','Brave');
$this->display();
}

function getinfoF(){
if (($res = F('_rules')) === false) {
$res = M("yyluyin")->where("lwr_id=94")->find();
F('_rules', $res);
}
return $res;
}

public function getinfoS($uid){
if(($res = S('_rules'.$uid)) === false){
$res = M("yyluyin")->where("lwr_id=94")->find();
S('_rules'.$uid,$res,'5');
}
return $res;
}

[/code]
************************快速缓存结束****************************************

八、序列化和反序列化

************************数组序列号处理****************************************
$_LOG['data'] = serialize($data); 把数组序列化
a:2:{i:0;s:22:"用户 - 用户管理 ";i:1;a:13:{s:5:"email";s:10:"112@qq.com";}}、
unserialize($vo['data']); 数组反序列化 得到数组
************************数组序列号处理****************************************

************************接收参数安全处理****************************************

escape(h(t( $_POST['lws_namecn'] )));

remove_xss
safe

************************接收参数安全处理****************************************

九、通过log进行ajax调试

AJAX 执行的页面可以通过日志的方式记录并调试

$this->trace('我很丑,但是我很温柔','5211314'); //把日志写入trace 信息中

Log::write("12323423",'NOTIC'); 可以在AJAX的时候使用 可以把信息写入日志,通过日志调试程序

十、令牌使用:

[code]
function bb(){
$user = M('ztest');
$user->create();
if($user->autoCheckToken($_POST)){
//判断是否存在令牌验证
session::set('__hash__','');
if($user->add()){
echo "Token Yes!!";
}
}else{
echo "Token No!!";
}
}
[/code]

十一、sql更新数值和字段内容:

[code]
$User = M("User"); // 实例化User对象

$User->setInc('score','id=5',3); // 用户的积分加3

$User->setInc('score','id=5'); // 用户的积分加1

$User->setDec('score','id=5',5); // 用户的积分减5

$User->setDec('score','id=5'); // 用户的积分减1

特殊sql执行
$bridegearr = array(
'lci_claend' => $end_time,
'lci_stuleav' => array('exp','lci_stuleav+1'),
);
$usr->where("id=1")->save($bridegearr);

$where = array(
'lwo_type' => array('in',array())
)
$user->where($where)->select
[/code]

十二、构造函数

_initialize 和 PHP5中的__Construct()

十三、AJAX使用加载和原始jquery冲突

[code]
1.使用需要加载文件:




2.解决冲突问题

[/code]

十四、SQL拼接使用

[code]
public function GetAutostuInfo($where,$field='*',$qtype='find',$limit='',$join='',$orderby='lws_createtime desc'){
//默认只获取1对1的订单
$this->field($field);
if(!empty($join)){
$this->join($join);
}
$this->where($where);
$this->order($orderby);
$this->limit($limit);
$return = $this->$qtype();
log::write($return,"学员信息自动查询");
return $return;
}
[/code]

标签:
上一篇:
下一篇: