• tp5中的一些小方法


    // 当使用一个新页面替换当前页面的body后,body刷新了,所选择的select值就不能保存住,解决方法如下:
        作业题目<select>
        <option>--请选择--</option>
        {if condition="$title"}    // 先将所选择的option传递到后台,在使用$tis->assign('title',$title)渲染到模板,
        <option selected="selected" style="display: none">{$title}</option>  在新页面选中该值,并隐藏,
        {/if}
        {volist name="data" id="coursejob"}
        <option>{$coursejob}</option>      //option中的选项是全的,所以要隐藏<option selected="selected" style="display: none">{$title}</option> 
     {/volist} </select>
    // tp5中url的写法
    <a href="{:url('admin/index')}?Id={$data['Id']}" >url写法</a><a href="{:url('index/download',['Id'=>$data['Id']])}">url的另一种写法</a>
    // 分页在数据查询时使用
    ->paginate(每页显示的记录数,查询总数);

    需要在模板中使用:
    {$data->render()}
    // tp5不加载模板的方法,在模板的开头写上:
    {__NOLAYOUT__}
    
    //tp5自动加载模板的方法,在配置文件中做如下配置:
    'template'=>[
            'layout_on'=>true,        // true表示自动加载模板
            'layout_name'=>'layout',     // 模板的名字,直接放在view目录下
        ],    
    // tp模板中if...else的用法
     {if condition="$data.Id === null"}
        ...
        {else/}
        ...
    {/if}
    //tp5在config总自定义的配置项,使用config()方法调用:
    config('自定义配置项')    // 在使用时,不能将config整个引起来
    // tp5cookie的使用方法:
    use thinkCookie;
    Cookie::set('name','chrdai',3600); //设置cookie
    cookie('name')    // 取出cookie
    Cookie::delete('name') // 删除cookie
    // tp5自定义常量,供模板中调用
    'view_replace_str'=>[
            '__APP__'=>'http://127.0.0.1/test/',
            '__PUBLIC__'=>'/test/testweb/public/',
    ]
    // thinkphp用msubstr截取,后面显示省略号
    /应用示例:
    
      <td title="{$vol.stem}">{$vol.stem|msubstr=0,15}</td>
    
    // 用法:
      msubstr($str, $start=0, $length, $charset=”utf-8″,$suffix=true)
      //$str:要截取的字符串
      //$start=0:开始位置,默认从0开始
      //$length:截取长度
      //$charset=”utf-8″:字符编码,默认UTF-8
      //$suffix=true:是否在截取后的字符后面显示省略号,默认true显示,false为不显示
    2.   {$vo.title|msubstr=5,5,’utf-8′,false}  这样使用, 则第五个字符之后,将会被截取,最后一个参数的话,设置为true则会显示省略号
  • 相关阅读:
    js-依次循环异步请求(普通/ES6)
    jquery
    js
    selenium
    selenium
    selenium
    python
    selenium
    selenium
    selenium
  • 原文地址:https://www.cnblogs.com/chrdai/p/6100966.html
Copyright © 2020-2023  润新知