thinkphp use php code

Php codes and labels can be mixed in the template file, you can write any statements in the template file inside PHP code, including the following two ways:

Optional linear motor

The first: use php tags

E.g:

  1. <php>echo 'Hello,world!';</php>

We recommend using PHP code when needed to maximize the use php tags because native PHP syntax may be configured to disable a result of parsing errors.

The second: use native php code
  1. <?php echo 'Hello,world!'; ?>

Note: php php code label or tag which no longer be used (including ordinary XML tags and labels), so the following ways are valid:

  1. <php><eq name='name'value='value'>value</eq></php>

Php label which uses the eqlabel, and therefore invalid

  1. <php>if( {$user} != 'ThinkPHP' ) echo 'ThinkPHP' ;</php>

Php label which uses a {$user}normal label output variables, and therefore invalid.

  1. <php>if( $user.name != 'ThinkPHP' ) echo 'ThinkPHP' ;</php>

Php label inside using $user.name dot syntax output variable, and therefore invalid.

In short, you can no longer use the code in PHP itself does not support PHP tags inside.

If you set the TMPL_DENY_PHPparameter to true, you can not use the native PHP code in the template, but still supports PHP tag output.

Guess you like

Origin www.cnblogs.com/furuihua/p/11834445.html