The request variables in the hyper-global array and Smarty in PHP

Source: Internet
Author: User

$_get <{$smarty .get}>

$_post <{$smarty .post}>

$_cookie <{$smarty .cookie}>

$_session <{$smarty .session}>

$_files (because the foreground is not available)

$_server <{$smarty .server}>

$_request <{$smarty .request}>

$_env <{$smarty .env}>

$GLOBALS No

Using the request variable in the Smarty template engine, you can request data directly without having to receive and redistribute from PHP

Example:

The code is as follows Copy Code

<{$smarty .get}>

PHP Way: $tpl->assign ("id", $_get[' id ');

<{$id}>

Smarty Request Variable mode: <{$smarty .get.id}>

2. <{$smarty .session}>

PHP Way: $_session[' name ']= "Marcofly";

The code is as follows Copy Code

$tpl->assign ("name", $_session[' name ');

<{$name}>//

Output to Template

Smarty Request Variable mode:

The code is as follows Copy Code

<{$smarty .session.name}>

Smarty the retention variable in the template engine <{$smarty}>:

<{$smarty .const}> can pass "." Access to any one of the constants (including custom and system constants)

Example:

The code is as follows Copy Code

<{$smarty .const.__file__}>

Define ("PI", 3.1415926); Defining PHP Constants

<{$smarty .const.pi}>//using Smarty Output constant PI

Smarty access to configuration files in two ways

The code is as follows Copy Code

Way a:<{##}>

Mode two: <{$smarty .config}>//retention variable form

Get the current server time:

You do not need to use PHP to get time from the server, simply use the Smarty retention variable to get

  code is as follows copy code

<{$ Smarty.now|date_format: "%y-%m-%d%h:%m:%s"}>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.