TP5伪静态路径写法

25 篇文章 1 订阅

 

路由设置:

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">

url使用js变量传参方法:

content: '{:url('main/editschool')}?id='+data.id,

  1. window.location.href="{:url('Index/index')}>"+"/ID/"+ID; //这样可以生成,但url模式改变则不能用

  2.  
  3. window.location.href="{:url('Index/index','ID=" + ID+ "')}" //解析不成功。

  4.  
  5. window.location.href="{:url('Index/detail',['id' => "+iD+"])}";//解析不成功

  6.  
  7. window.location.href='{:url("Index/detail")}?id='+ iD ;//解析成功

另外一种方法: 

  1. var pid = 3;//要带入的变量

  2. var str = "{:url('Index/detail',array('id'=>'p_id'))}"; //先将变量以字符串的形式带入U函数中

  3. str1 = str.replace("P_id",pid); //将代替变量的字符串用真实变量替换掉,OK搞定!

  4. $("#city_id").load(str1);

  5.  
  6. 或者

  7.  
  8. var pid = 3;

  9. var str = "{:url('Index/detail')}";

  10. $("#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",

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值