php section

 介绍php section使用

{section name = name loop = $varName[, start = $start, step = $step, max = $max, show = true]} 

name: section的名称,不用加$
$loop: 要循环的变量,在程序中要使用assign对这个变量进行操作。
$start: 开始循环的下标,循环下标默认由0开始
$step: 每次循环时下标的增数
$max: 最大循环下标

$show: boolean类型,决定是否对这个块进行显示,默认为true 

 

 

例子 

 配置文件

<? php
$attach_sort [ 0 ][ ' id ' ] = 0 ;
$attach_sort [ 0 ][ ' name ' ] = " 全部 " ;
$attach_sort [ 0 ][ ' num ' ] = 30 ;
$attach_sort [ 1 ][ ' id ' ] = 1 ;
$attach_sort [ 1 ][ ' name ' ] = " 用户通讯 " ;
$attach_sort [ 1 ][ ' num ' ] = 30 ;
$attach_sort [ 2 ][ ' id ' ] = 2 ;
$attach_sort [ 2 ][ ' name ' ] = " 文献综述 " ;
$attach_sort [ 2 ][ ' num ' ] = 30 ;
$attach_sort [ 3 ][ ' id ' ] = 2 ;
$attach_sort [ 3 ][ ' name ' ] = " 认证认可 " ;
$attach_sort [ 3 ][ ' num ' ] = 30 ;
$attach_sort [ 4 ][ ' id ' ] = 2 ;
$attach_sort [ 4 ][ ' name ' ] = " 仪器资料 " ;
$attach_sort [ 4 ][ ' num ' ] = 30 ;
$attach_sort [ 5 ][ ' id ' ] = 2 ;
$attach_sort [ 5 ][ ' name ' ] = " 实验方法 " ;
$attach_sort [ 5 ][ ' num ' ] = 30 ;
$attach_sort [ 6 ][ ' id ' ] = 2 ;
$attach_sort [ 6 ][ ' name ' ] = " 分析方法 " ;
$attach_sort [ 6 ][ ' num ' ] = 30 ;
$attach_sort [ 7 ][ ' id ' ] = 2 ;
$attach_sort [ 7 ][ ' name ' ] = " 标准 " ;
$attach_sort [ 7 ][ ' num ' ] = 30 ;
$attach_sort [ 8 ][ ' id ' ] = 2 ;
$attach_sort [ 8 ][ ' name ' ] = " 会议论文 " ;
$attach_sort [ 8 ][ ' num ' ] = 30 ;
$attach_sort [ 9 ][ ' id ' ] = 2 ;
$attach_sort [ 9 ][ ' name ' ] = " 课件讲义 " ;
$attach_sort [ 9 ][ ' num ' ] = 30 ;
 
 
$smarty -> assign( " attach_sort " ,   $attach_sort );       // 分类

 
?>

 html 模板

{section name=sort  loop=$attach_sort}
< href ="list.php?sort={$attach_sort[sort].id}{if $keyword}&keyword={$keyword}{/if}"  {if $sort =={$attach_sort[sort].id}}class="fox"{/if} > {$attach_sort[sort].name} </ a >
{/section}

 

转载于:https://www.cnblogs.com/ly312/archive/2011/04/07/2007546.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PHPWord 是一款用于动态生成和操作 Microsoft Word 文档的 PHP 库。在生成 Word 文档时,有时候需要在文档的开头添加一个目录,以便读者可以快速查找到各个部分的内容。下面是使用 PHPWord 生成目录的步骤: 1. 首先,我们需要创建一个新的 PHPWord 对象: ```php $phpWord = new \PhpOffice\PhpWord\PhpWord(); ``` 2. 在创建文档的过程中,我们可以使用 `$phpWord->addTableOfContents` 方法来添加目录。该方法接受一个参数,用于设置目录的格式。例如,可以指定标题的字体、字号和样式: ```php $section = $phpWord->addSection(); $section->addText('Contents', array('size' => 24, 'bold' => true)); $tableOfContents = $section->addTableOfContents(array('fontSize' => 12, 'marginLeft' => 96, 'tabLeader' => \PhpOffice\PhpWord\Style\TOC::TABLEADER_DOT)); ``` 3. 在生成文档的过程中,可以使用 `$section->addText` 方法来添加正文内容。 ```php $section->addText('Section 1'); $section->addText('Section 2'); $section->addText('Section 3'); ``` 4. 最后,在生成文档的任意位置,可以使用 `$section->addTOC` 方法来插入目录。这将创建一个可点击的目录链接。 ```php $section->addTOC(); ``` 5. 最后,我们将生成的 Word 文档保存到服务器或者下载到本地: ```php $writer = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $writer->save('path/to/save/document.docx'); ``` 以上就是使用 PHPWord 生成目录的基本步骤。通过添加目录,我们可以方便地在 Word 文档中导航和查找各个部分的内容。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值