测试一下一栏是我创建的一个插件选项,但是点击后,总是跳转不到我想要的样子。然后,我点击测试一下的时候,没有跳转过去
而是显示的是“通知管理”的界面
这是我添加的controller文件。
这是test.html文件
我觉得所有的步骤都是正确的,却出现了莫名奇妙的问题。
最后把这些都删除了,重新创建了“TestExample”,把schoolcard里面的代码复制过来,做一些小调整,然而却成功的能访问了,我不知道内部的原理是什么,我猜测可能是我的代码写得不规范的原因,以下是我的代码:
userview.html
在服务器的/Application/Home/View/default/TestExample/下
<extend name="Base/common" />
<block name="body">
<div class="span9 page_message">
<section id="contents"> <include file="Addons/_nav" />
<div class="table-bar">
<!-- 高级搜索 -->
<div class="search-form fr cf">
<div class="sleft">
<php>empty($search_key) && $search_key=$model['search_key'];empty($search_key) && $search_key='title';</php>
<input type="text" name="{$search_key}" class="search-input" value="{:I($search_key)}" placeholder="请输入关键字">
<a class="sch-btn" href="javascript:;" id="search" url="{:U('userview',array('model'=>$model['name']))}"><i class="btn-search"></i></a>
</div>
</div>
</div>
<!-- 数据列表 -->
<div class="data-table">
<div class=" table-striped">
<table cellpadding="0" cellspacing="1">
<!-- 表头 -->
<thead>
<tr>
<th width="20%">丢卡人姓名</th>
<th width="20%">丢卡人学号</th>
<th width="20%">发布时间</th>
<th width="20%">捡卡地点</th>
<th width="20%">捡卡人手机号</th>
</tr>
</thead>
<!-- 列表 -->
<tbody>
<volist name="list_data" id="data" ><!-- -->
<tr>
<td>{$data.name}</td>
<td>{$data.studentid}</td>
<td>{$data.ctime|time_format}</td>
<td>{$data.location}</td>
<td>{$data.phone}</td>
</tr>
</volist>
</tbody>
</table>
</div>
</div>
<div class="table-bar" style="margin-bottom:20px">
<div class="fl">
<div class="page" style="margin:0"> {$_page|default=''} </div>
</div>
</div>
</section>
</div>
</block>
<block name="script">
<script type="text/javascript">
$(function(){
//搜索功能
$("#search").click(function(){
var url = $(this).attr('url');
var query = $('.search-form').find('input').serialize();
query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
query = query.replace(/^&/g,'');
if( url.indexOf('?')>0 ){
url += '&' + query;
}else{
url += '?' + query;
}
window.location.href = url;
});
//回车自动提交
$('.search-form').find('input').keyup(function(event){
if(event.keyCode===13){
$("#search").click();
}
});
})
</script>
</block>
在服务器的/Application/Home/Controller/目录下
<?php
namespace Home\Controller;
/**
* 前台首页控制器
* 主要获取首页聚合数据
*/
class TestExampleController extends HomeController {
public function common()
{
$res ['title'] = '校园小资讯';
$res ['url'] = U ( 'home/TestExample/userview' );
$res ['class'] = 'current';
$nav [] = $res;
$this->assign ( 'nav', $nav );
$this->assign ( 'notadmin', get_mid() != C('USER_ADMINISTRATOR'));
}
private function is_admin(){
return get_mid() == C('USER_ADMINISTRATOR');
}
// 通用插件的删除模型
public function del() {
parent::common_del ($this->getModel('ccnu_SchoolCard'));
}
public function edit() {
parent::common_edit ($this->getModel('ccnu_SchoolCard'));
}
public function userview()
{
//获取院系uid
$usid =get_mid();
$dep= M('ccnu_department')->where('deuid='.$usid)->find();
$num = $dep['id'];
$model = M('ccnu_schoolcard');
$count = $model->where('aimdepartment='.$num)->count ();
$page = I ( 'p', 1, 'intval' );
$row = 20;
$list_data = $model->where('aimdepartment='.$num)->select();
// 分页
if ($count > $row) {
$page = new \Think\Page ( $count, $row );
$page->setConfig ( 'theme', '%HEADER%' );
$this->assign ( '_page', $page->show () );
}
$this->assign ( 'list_data',$list_data );
$this->common();
$this->display();
}
public function download()
{
$model = M('ccnu_department');
$usid =get_mid();
$dep= $model->where('deuid='.$usid)->find();
$num = $dep['id'];
$model = M("ccnu_student");
$lists = $model->where('department='.$num)
->field('wp_ccnu_student.name,wp_ccnu_student.studentid,wp_ccnu_student.major,wp_ccnu_student.mobile')
->select();
header("Content-type:text/csv");
header("Content-Disposition:attachment;filename=校园卡管理列表.csv");
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
$data= $this->toGB2312("姓名,学号,专业,手机\n");
foreach($lists as $k=>$v){
$data.=$this->toGB2312("{$v['name']},{$v['studentid']},{$v['major']},{$v['mobile']}\n");
}
echo $data;
return;
}
private function toGB2312($data)
{
return iconv('UTF-8', 'GB2312//IGNORE',$data);
}
}
结果: