个人用的一些代码分享。

浏览:704 发布日期:2016/06/16 分类:技术分享 关键字: 使用代码 代码分享 小代码
修改TP自带的提示页面修改代码。
'TMPL_ACTION_SUCCESS' => 'Public:jump',
'TMPL_ACTION_ERROR' => 'Public:jump',


在config里面写上。
然后在每个分组里面的Public里面写一个Jump的html页面
<?php
if(C('LAYOUT_ON')) {
echo '{__NOLAYOUT__}';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>跳转提示</title>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
body {
background: #fff;
font-family: '微软雅黑';
color: #333;
font-size: 16px;
}
.system-message {
position:absolute;
top:50%;
left:50%;
margin:-150px 0 0 -150px;
width:300px;
height:300px;
text-align:center;
}
.system-message h1 {
font-size: 120px;
font-weight: normal;
}
.system-message .jump {
padding-top: 10px
}
.system-message .jump a {
color: #09C;
text-decoration:none
}
.system-message .success, .system-message .error {
line-height: 1.8em;
font-size: 36px
}
.system-message .detail {
font-size: 12px;
line-height: 20px;
margin-top: 12px;
display:none
}
</style>
</head>
<body>
<div class="system-message">
<?php if(isset($message)) {?>
<h1>√</h1>
<p class="success"><?php echo($message); ?></p>
<style>
.system-message{border:3px solid #09C;}
.system-message h1{ color: #09C;}
</style>
<?php }else{?>
<h1>×</h1>
<p class="error"><?php echo($error); ?></p>
<style>
.system-message{border:3px solid #F33;}
.system-message h1{ color: #F33;}
</style>
<?php }?>
<p class="detail"></p>
<p class="jump"> 页面自动 <a id="href" href="<?php echo($jumpUrl); ?>">跳转</a> 等待时间: <b id="wait"><?php echo($waitSecond); ?></b> </p>
</div>
<script type="text/javascript">
(function(){
var wait = document.getElementById('wait'),href = document.getElementById('href').href;
var interval = setInterval(function(){
var time = --wait.innerHTML;
if(time <= 0) {
location.href = href;
clearInterval(interval);
};
}, 1000);
})();
</script>
</body>
</html>
直接弹框提示代码:



$this->show("<script>alert('请填写优先级!')</script>");//出提示信息
echo "<script>history.back();</script>";exit;//跳转页面

弹框。并且回到当前页面


$this->show("<script>alert('修改成功!')</script>");//出提示信息
echo "<script>location.href='".U('index')."'</script>";exit;//跳转页面

在TP中直接写sql语句:
我举例说明,你举一反三即可
直接查询:
public function v(){
$Form=M();
$sql="select * from news ";
$list =$Form->query($sql);
$this->assign('list',$list);
$this->display();
}

条件查询:
public function v(){
$id=$_GET['i'];
$Form=M();
$sql="select * from news where id=".$id."";
$list =$Form->query($sql);
$this->assign('list',$list);
$this->display();
}

分页查询:
public function l(){
import("@.ORG.Page"); //导入分页类
$Form=M();
$sql="select * from goods order by id asc";
$list =$Form->query($sql);
$count = count($list); //计算总数
$p = new Page ($count, 5);
$up=$p->firstRow; //开始条数
$down=$p->listRows;//结束条数
$sql=$sql.' limit '.$up.','.$down.' ';
$list =$Form->query($sql);
$page = $p->show ();
$this->assign ( "page", $page );
$this->assign ( "list", $list );
$this->display();
}
select * from student inner join course on student.ID=course.ID

点击打印功能:
<a href="#" onclick="window.print();">打印</a>
滚动条定位:
<script>
window.onload = function()
{
var aWidth = window.screen.availWidth; // 获取客户端分辨率的宽度
var aHeight = window.screen.availHeight; // 获取客户端分辨率的高度
var sWidth = document.body.scrollWidth; // 获取浏览器的宽度
var sHeight = document.body.scrollHeight; // 获取浏览器的高度
var tWidth = sWidth - aWidth;
var tHeight = sHeight - aHeight;
window.scrollTo((tWidth / 1), (tHeight / 1));
}
</script>
获取数据库某一列数据:
$ww=$jieguo['id'] ;
判断PC以及手机和平板:
//移动端适配URL跳转js代码
<script type="text/javascript">
if(window.location.toString().indexOf('?pad') != -1){
}else{
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?mobile")<0){
try{
if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
window.location.href="手机页面";
}else if(/iPad/i.test(navigator.userAgent)){
window.location.href="平板页面"
}else{
window.location.href="其它移动端页面"
}
}catch(e){}
}
}
}
</script>


判断手机和电脑
?<script type="text/javascript">

function mobile_device_detect(url){
var thisOS=navigator.platform;
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
for(var i=0;i<os.length;i++){
if(thisOS.match(os[i])){
window.location=url;
}
}
if(navigator.platform.indexOf('iPad') != -1){
window.location=url;
}
var check = navigator.appVersion;
if( check.match(/linux/i) ){
if(check.match(/mobile/i) || check.match(/X11/i)) {
window.location=url;
}
}
Array.prototype.in_array = function(e){
for(i=0;i<this.length;i++){
if(this[i] == e)
return true;
}
return false;
}
}
mobile_device_detect("http://eqxiu.com/s/L15FSy");/*指定跳转地址*/
</script>
拼接数组:
$bb=M('Price')->where('shenhe=1 and yid=1')->order('id desc')->limit(2)->select();
foreach($bb as $k => $v){
$cid=!empty($v['cid']) ? $v['cid'] : '';
$nn=M('PriceClass')->where("id =$cid")->order('id desc')->limit(1)->find();
$bb[$k]['classname'] = !empty($nn['classname']) ? $nn['classname'] : '';
}
$this->bbb=$bb;
删除数据同时删除图片:

//新闻批量删除
public function newsDel(){
$ids=$_POST['ids'];
$condition['picName']=array('in',$ids);
foreach($condition['picName'][1] as $k => $v){
$file="./web/Uploads/PPT/{$v}";

if (!unlink($file))
{
echo ("Error deleting $file");
}
}
foreach($condition['picName'][1] as $k => $v){

$file="./web/Uploads/PPT/thumb_{$v}";
if (!unlink($file))
{
echo ("Error deleting $file");
}
}

//dump($$condition['picName'][1]);exit;
$ids=$_POST['ids'];
$condition['picName']=array('in',$ids);
M('Bnnar')->where($condition)->delete();

$this->show("<script>alert('删除成功!')</script>");//出提示信息
echo "<script>location.href='".U('index')."'</script>";exit;//跳转页面


}
<td align="center" ><input type="checkbox" name="ids[]" value="{$vo.picName}" /></td>
//单个删除

public function Del(){
$ll=I('picName');
$file="./web/Uploads/PPT/{$ll}";
$file1="./web/Uploads/PPT/thumb_{$ll}";
if (!unlink($file))
{
echo ("Error deleting $file");
}
if (!unlink($file1))
{
echo ("Error deleting $file");
}
//unlink($picName);

//unlink('./web/Uploads/PPT/'.$thumb["picName"]);
//dump($thumb);exit;
$id=I('id',0);

$m=M('Bnnar');
if($m->where("fid={$id}")->select()){
$this->show("<script>alert('禁止删除!')</script>");//出提示信息
echo "<script>location.href='".U('index')."'</script>";exit;//跳转页面
}else{
$m->where("id={$id}")->delete();

$this->show("<script>alert('删除成功!')</script>");//出提示信息
echo "<script>location.href='".U('index')."'</script>";exit;//跳转页面
}
}

<a href="{:U('Admin/Bnnar/Del',array('id'=>$vo['id'],'picName'=>$vo['picName']))}" onclick="return confirm('确定删除吗??')"> <span style="color:#F00">删除</span></a>

在控制器生成随机验证码:
<?php
function randomkeys($length){
$pattern='1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ,./<>?;#:@~[]{}-_=+)(*&^%___FCKpd___0pound;"!'; //字符池
for($i=0;$i<$length;$i++){
$key.=$pattern{mt_rand(0,35)};//生成php随机数
}
return $key;
}
$yy=randomkeys(8);
echo $yy;
?>
最佳答案
评论( 相关
后面还有条评论,点击查看>>