添加分页:
public function recharge_record(){
$uid=is_login();
$result=M('money_action')->where('uid='.$uid)->order('time desc')->select();
$count=count($result);
$Page= new \Think\Page($count,8);
$show = $Page->show();
$i=M('money_action')->where('uid='.$uid)->order('time
desc')->limit($Page->firstRow.','.$Page->listRows)->select();
//var_dump($i);die();
foreach ($i as $key => $value) {
$list[]=$value;
}
$this->assign('list',$list);
$this->assign('page',$show);
$this->display();
}
前台调用:
<volist name="list" id="vo">
<tr>
<td class="date">{$vo.time} </td>
<td class="money1">{$vo.change}</td>
<td class="source">{$vo.why}</td>
</tr>
</volist>
{$page}
文章:
public function index($p=1){
$category = $this->category();
/* 获取当前分类列表 */
$Document = D('Document');
$list = $Document->page($p,8)->lists($category['id']);
if(false === $list){
$this->error('获取列表数据失败!');
}
/* 模板赋值并渲染模板 */
$this->assign('category', $category);
$this->assign('list', $list);
//$this->display($category['template_lists']);
$this->display('notice');
}
前台调用:
<volist name="list" id="article">
<li class="fn-clear">
<h3 class="wraptitle">{$article.title}</h3>
<p>{$article.id|get_content}</p>
<span>{$article.create_time|date='Y-m-d',###}</span>
</li >
</volist>
<article:page cate="$category['id']" listrow="8" />
连表查询:
$prefix = C('DB_PREFIX');
$l_table = $prefix.('ucenter_member');
$r_table = $prefix.('money');
$info= M() ->table( $l_table.' l' )
->where('id='.$uid)
->join ( $r_table.' r ON l.id=r.uid' )
// ->field('l.username,l.wuxian,r.balance')
->find();
$prefix = C('DB_PREFIX');
$l_table = $prefix.('products_action');
$r_table = $prefix.('ucenter_member');
$i= M() ->table( $l_table.' l' )
->where('l.product_id='.$peitao.' and l.status=0')
->join ( $r_table.' r ON l.uid=r.id' )
->field('l.uid,l.title,l.time,l.allday,r.username')
->order('l.time desc')
->limit($Page->firstRow.','.$Page->listRows)
->select();
数据库配置有两个地方:Application/Common/Conf/config.php
和 Application/User/Conf/config.php
关闭浏览器缓存: 文件在ThinkPHP/Conf/convention.php
实现时分倒计时:
一:
<SCRIPT LANGUAGE="JavaScript">
var maxtime = 302; //一个小时,按秒计算,自己调整!
function CountDown(){
if(maxtime>=0){
minutes = Math.floor(maxtime/60);
seconds = Math.floor(maxtime%60);
msg = "距离结束还有"+minutes+"分"+seconds+"秒";
document.all["timer"].innerHTML=msg;
if(maxtime == 5*60) alert('注意,还有5分钟!');
--maxtime;
}
else{
clearInterval(timer);
alert("时间到,结束!");
}
}
timer = setInterval("CountDown()",1000);
</SCRIPT>
<div id="timer" style="color:red" mce_style="color:red"></div>
二:
<SCRIPT LANGUAGE="JavaScript">
setInterval("time_controller()",1000);
function time_controller(){
$(".time_val").each(function(){
var time_id = "time_show_"+$(this).attr('for');
var time_val= $(this).attr('value');
$(this).attr('value',time_val-1);
show_time(time_id,time_val*1000);
});
}
function show_time(id,timestamp)
{
var timer = document.getElementById(id);
var str_time,int_day,int_hour,int_minute,int_second;
var time_distance = timestamp;
if(time_distance>0)
{
int_day=Math.floor(time_distance/86400000)
time_distance-=int_day*86400000;
int_hour=Math.floor(time_distance/3600000)
time_distance-=int_hour*3600000;
int_minute=Math.floor(time_distance/60000)
time_distance-=int_minute*60000;
int_second=Math.floor(time_distance/1000)
if(int_hour<10)
int_hour="0"+int_hour;
if(int_minute<10)
int_minute="0"+int_minute;
if(int_second<10)
int_second="0"+int_second;
str_time="<b>剩余时间:"+int_day+"天"+int_hour+"小时"+int_minute+"分钟"+int_second+"秒</b>";
timer.innerHTML=str_time;
}else{
timer.innerHTML="<b>剩余时间: 0天0小时0分钟0秒</b>";
}
}
</SCRIPT>
<div class="time" id="time_show_{$list.cmd_id}"></div>
<input type="hidden" class="time_val" for="{$list.cmd_id}" value="{$list.time_val}" />
分页深层使用:
$Page= new \Think\Page($count,2);
$Page->setConfig('prev','上一页');
$Page->setConfig('next','下一页');
$show = $Page->show();
$show=substr($show,5,-6);
$i=M('ucenter_member')->where('group_id=0')->order('reg_time
desc')->limit($Page->firstRow.','.$Page->listRows)->select();
$count_page=$Page->totalPages;
防止浏览器自动填写表单:
写两个隐藏的<input>让他填充;
数据库允许外部访问:
1、打开mysql.exe(MySQL Command Line Client),输入密码
2、输入:use mysql;
3、查询host输入: select user,host from user;
4、创建host(如果有"%"这个host值,则跳过这一步)
如果没有"%"这个host值,就执行下面这两句:
mysql> update user set host='%' where user='root';
mysql> flush privileges;
5、授权用户
(1)任意主机以用户root和密码pwd连接到mysql服务器
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'pwd' WITH GRANT OPTION;
mysql> flush privileges;
(2)指定IP为(如192.168.1.100)的主机以用户tuser和密码tpwd连接到mysql服务器
mysql> GRANT ALL PRIVILEGES ON *.* TO 'tuser'@'192.168.1.100' IDENTIFIED BY 'tpwd' WITH GRANT OPTION;
mysql> flush privileges;
搜索功能:
问题:搜索结果和原页面是同一个页面,对搜索结果分页后,点击下一页,搜索就
没有作用了。因为分页链接里没带post参数,过去后,就按照没有搜索处理了。
解决方法:最好要对搜索结果单独做一个页面。
不行的话搜索结果就不要分页。
完美解决方法!!:带查询的分页链接(详情参考http://www.thinkphp.cn/topic/34467.html)
TP框架上线后一定要注意缓存:
简单粗暴的方式是直接删除runtime。
更换数据结构、类型要清除数据缓存,位置大概是runtime下的data,否则操作无法正常完成。
从服务器上拿下来的网站再次上传到服务器上:
清缓存,如果路径有错的,仔细查看是否区分大小写。
Mysql定时任务:
执行查询(整段执行):
-- 开启定时任务
SET GLOBAL event_scheduler = ON;
-- 显示事件
show variables like 'event_scheduler';
-- 删除事件
DROP EVENT IF EXISTS `myevent`;
-- 创建事件
CREATE EVENT IF NOT EXISTS myevent
ON SCHEDULE EVERY 1 DAY
STARTS TIMESTAMP(CURRENT_DATE,'00:00:00')
DO
delete from `ncj_order` where `uid`=115;
PHPstorm中断点调试设置:
Php.ini:
[XDebug]
zend_extension = "F:\xampp\php\ext\php_xdebug.dll"
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "F:\xampp\tmp"
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "localhost"
xdebug.trace_output_dir = "F:\xampp\tmp"
xdebug.idekey = PHPSTORM
xdebug.remote_port=9001
(出现wating for incoming ide key xxx 很可能是xdebug.remote_enable = 0 或者 未设置断点 或者浏览器的debug工具不对:谷歌建议使用xdebug help)
AJAX请求 跨域问题(情况是返回的时候没有执行success,而是进入error):
http://www.cnblogs.com/go-jzg/p/4594723.html
语言包
第一步:项目目录中:Application/home/conf/config.php或者Application/index/conf/config.php,加入代码:
'LANG_SWITCH_ON' => true, //开启语言包功能
'LANG_AUTO_DETECT' => true, // 自动侦测语言
'DEFAULT_LANG' => 'zh-cn', // 默认语言
'LANG_LIST' => 'en-us,zh-cn,zh-tw', //必须写可允许的语言列表
'VAR_LANGUAGE' => 'l', // 默认语言切换变量
第二部:Application/home/conf/tags.php或者Application/index/conf/tags.php,添加:
'app_begin' => array('Common\Behavior\CheckLangBehavior'),
第三部:再把thinkphp中的Library中的Behavior\Checklangbehavior文件拷贝到:application/common/behavior中:注意这个类文件:namespase改写成:namespace Common\Behavior;
use Think\Behavior;
use Think\Hook;很重要:不然 找不到类文件 显示NOT FOUND;
第四部:application/index或者home中,建立lang文件夹:并建立:zh_cn.PHP文件,默认读取此文件:文件中:
return array(
'SITE_title' => '杭州宣萌',
'_SITE_URL_' => 'http://www.hzxuanmeng.com/',
'SITE_QQ' => '2397196338小明',
在控制器中写入:
echo L('_SITE_URL_');
或者在模板文件中写入:{:L("SITE_QQ")}