路由设置:
route.php
<?php
// ThinkAdmin
use think\facade\Request;
use think\facade\Route;
//定义路由规则
//企业站
Route::rule('about/[:cateid]','index/index/about');
Route::rule('yuanli/[:cateid]','index/index/yuanli');
Route::rule('fangan/[:cateid]','index/index/fangan');
Route::rule('jiameng/[:cateid]','index/index/jiameng');
Route::rule('lianxi/[:cateid]','index/index/lianxi');
Route::rule('jianjie/[:cateid]','index/index/jianjie');
Route::rule('xiangqing/:id','index/index/xiangqing');
//商城
Route::rule('shopxq/:id','shop/shop/shopxq'); //详情
Route::rule('cate/[:pid]/[:id]/[:onShelf]/[:sale]/[:fontprice]','shop/shop/cate');
//二级分类
Route::rule('login','shop/shop/login'); //登录
Route::rule('checklogin','shop/shop/checklogin'); //检测登录
Route::rule('phonesms','shop/shop/phonesms'); //获取短信验证码
Route::rule('register','shop/shop/register'); //注册
Route::rule('checkregister','shop/shop/checkregister'); //注册
Route::rule('shopmore/[:type]/[:onShelf]/[:sale]/[:fontprice]','shop/shop/shopmore');
//首页更多跳转 热卖 新品 精选
Route::rule('help/[:id]','shop/shop/help'); //帮助中心
Route::rule('vip/[:type]','shop/shop/vip'); //会员中心
Route::rule('vip2','shop/shop/vip2'); //会员中心
Route::rule('order','shop/shop/order'); //我的订单
模板页面使用:
例一:
{:url('shop/shop/vip',['type'=>1])}
<a href="{:url('shop/shop/vip',['type'=>1])}" >订单管理</a>
例二:
{:url('/vip',['type'=>1])}
<a href="{:url('/vip',['type'=>1])}" >订单管理</a>
例三:
var name=$('#search').val()
window.location.href="{:url('/search')}?name="+ name
<script>
$(document).ready(function () {
$("#search").keypress(function (e) {
if (e.which == 13) {
var name=$('#search').val()
window.location.href="{:url('/search')}?name="+ name
}
});
})
$('.tovplay').click(function(){
if('{$Think.session.phone}'){
var mid='{$Think.session.id}'
var id=$(this).attr('data-id')
var type=$(this).attr('data-type')
window.location.href ="{:url('/vplay/"+id+"/"+type+"')}"
}else{
window.location.reload()
}
})
</script>
参考文章: https://blog.csdn.net/haibo0668/article/details/78052850/
参考文章:https://www.jb51.net/article/187356.htm
TP5 url链接(带参数)的写法
{:url('Liuyan/add')}
例子:<form class="layui-form" action="{:url('adminuser/adduser')}" id="jwForm">
content: '{:url('main/editschool')}?id='+data.id,
-
window.location.href="{:url('Index/index')}>"+"/ID/"+ID; //这样可以生成,但url模式改变则不能用
-
window.location.href="{:url('Index/index','ID=" + ID+ "')}" //解析不成功。
-
window.location.href="{:url('Index/detail',['id' => "+iD+"])}";//解析不成功
-
window.location.href='{:url("Index/detail")}?id='+ iD ;//解析成功
另外一种方法:
-
var pid = 3;//要带入的变量
-
var str = "{:url('Index/detail',array('id'=>'p_id'))}"; //先将变量以字符串的形式带入U函数中
-
str1 = str.replace("P_id",pid); //将代替变量的字符串用真实变量替换掉,OK搞定!
-
$("#city_id").load(str1);
-
或者
-
var pid = 3;
-
var str = "{:url('Index/detail')}";
-
$("#city_id").load(str, {"id" : pid});
生成url 带入多个参数:
模板:a href="{:url('edit',array('id'=>$admin['id']))}" class="btn btn-primary btn-sm shiny">
Url::build('index/detail/5',['id'=>1,'name'=>'thinkphp']);
出处:http://blog.csdn.net/haoaiqian/article/details/62881647
php中带参数跳转
$this->success('新增项目成功',url("Version/index",array('project_name'=>$project_name)));die;
$this->success('成功!',url('editschool',['id'=>$id]));
还有一种:如何传递参数 "url": "main/school.html?id=100",