php smarty fetch,fetch - [ smarty完全中文手册 ] - 在线原生手册 - php中文网

本文详细介绍了Smarty模板引擎中的fetch函数用法,包括从本地文件系统、HTTP或FTP获取文件内容,并展示了如何通过assign属性将获取的内容赋值给模板变量。

fetch

Attribute Name

Type

Required

Default

Description

file

string

Yes

n/a

the file, http or ftp site to fetch

assign

string

No

n/a

the template variable the output will be assigned

to

属性

类型

是否必须

缺省值

描述

file

string

Yes

n/a

待请求的文件,http或ftp方式.

assign

string

No

n/a

输出值将被赋给模板变量的名称

fetch is used to fetch files from the local file system, http, or ftp and display

the contents. If the file name begins with "http://", the web site page will

be fetched and displayed. If the file name begins with "ftp://", the file

will be fetched from the ftp server and displayed. For local files, the full

system file path must be given, or a path relative to the executed php script.

fetch 用于从本地文件系统、HTTP或FTP上取得文件并显示文件的内容. 如果文件名称以"http://"开头,将取得该网站页面并显示.

如果文件名称以"ftp://"开头,将从ftp服务器取得该文件并显示.

If you supply the special "assign" attribute, the output of the fetch function

will be assigned to this template variable instead of being output to the

template. (new in Smarty 1.5.0)

如果指定了 "assign" 这个特殊属性,该函数的输出值将被赋给由 assign 指定的模板变量,而不是直接输出.(Smarty 版本

1.5.0 新特性)

Technical Note: This will not support http redirects, be sure to include a trailing slash on

your web page fetches where necessary.

技术要点: 该函数不支持HTTP重定向,如果要取得web默认页,比如想取得www.domain.com的主页资料,但是不知道主页的具体名称,可能是index.php或index.htm或default.php等等,可以直接使用该站点的url,记得在url结尾处加上反斜线.

Technical Note: If template security is turned on and you are fetching a file from the local

file system, this will only allow files from within one of the defined

secure directories. ($secure_dir)

技术要点: 如果模板的安全设置打开了,当取本地文件时只能取位于定义为安全文件夹下的资料. ($secure_dir)

Example 8-5. fetch

例 8-5. fetch 函数演示

{* include some javascript in your template *}

{fetch file="/export/httpd/www.domain.com/docs/navbar.js"}

{* embed some weather text in your template from another web site *}

{fetch file="http://www.myweather.com/68502/"}

{* fetch a news headline file via ftp *}

{fetch file="ftp://user:password@ftp.domain.com/path/to/currentheadlines.txt"}

{* assign the fetched contents to a template variable *}

{fetch file="http://www.myweather.com/68502/" assign="weather"}

{if $weather ne ""}

{$weather}

{/if}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值