国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

smarty創(chuàng)建模板,將常用的數(shù)據(jù)類型渲染輸出

Original 2019-09-03 15:53:26 330
abstract:1、配置文件<?php require './vendor/autoload.php'; $smarty = new Smarty(); $smarty->setTemplateDir('./temp'); $smarty->setCompileDir('./temp_c'); $smar

1、配置文件

<?php

require './vendor/autoload.php';
$smarty = new Smarty();

$smarty->setTemplateDir('./temp');
$smarty->setCompileDir('./temp_c');
$smarty->setCacheDir('./cache');
$smarty->setConfigDir('./config');

$smarty->setLeftDelimiter('<{');
$smarty->setRightDelimiter('}>');

$smarty->setCaching(false);
$smarty->setCacheLifetime(60*60*24);

//echo print_r($smarty->getTemplateDir(),true);
//echo '<hr>';
//echo $smarty->getCompileDir();
//echo '<hr>';
//echo $smarty->getCacheDir();
//echo '<hr>';
//echo print_r($smarty->getConfigDir(),true);

2、PHP

<?php
session_start();
//加載Smart配置

require 'config/config.php';

//變量
$name = '中國';
$smarty->assign('names',$name);

//索引數(shù)組
$country = ['中國','俄羅斯','美國','加拿大','日本','韓國'];
$smarty->assign('country',$country);

//關聯(lián)數(shù)組
$area = [
    'first'=>'俄羅斯',
    'second'=>'加拿大',
    'third'=>'中國',
    'fourth'=>'美國'
];
$smarty->assign('area',$area);

//二維數(shù)組
$price = [
    ['name'=>'西紅柿','price'=>3],
    ['name'=>'黃瓜','price'=>5],
    ['name'=>'茄子','price'=>6]
];
$smarty->assign('price',$price);

//對象
class Test
{
    public $site= 'www.baidu.com';
    public function welcome ()
    {
        return '歡迎訪問:' .$this->site;
    }

}
$test = new Test();
$smarty->assign('test',$test);

function add($a,$b)
{
    return $a + $b;
}

const SITE_NAME = 'BAIDU';

$_POST['user_name'] = 'admin';
$_GET['page'] = 5;
$_SESSION['pass'] = sha1(123456);

$smarty->display('book2.html');

3、模板文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>book2</title>
</head>
<body>

<{* 顯示變量 *}>
<h3>我來自:<span style="color: red;"><{$names}></span></h3>

<{* 顯示索引數(shù)組 *}>
<p>國家有哪些:<{$country[0]}>,<{$country[1]}>,<{$country[2]}></p>

<{* 顯示關聯(lián)數(shù)組 *}>
<p>面積排行榜:</p>
<p>第一:-----><{$area.first}></p>
<p>第二:-----><{$area.second}></p>
<p>第三:-----><{$area.third}></p>
<p>第四:-----><{$area.fourth}></p>

<{* 顯示二維數(shù)組 *}>
<p>蔬菜價格</p>
<p>品名:<{$price.0.name}> 價格:<{$price.0.price}></p>

<{* 顯示對象 *}>
<p><{$test->site}></p>
<p><{$test->welcome()}></p>

<p><{$price.0.price + 10}></p>
<p><{str_replace('.','-',$test->site)}></p>
<p><{add(5,9)}></p>
<p><{$smarty.const.SITE_NAME}></p>

<{config_load file = "app.conf"}>
<p><{$smarty.config.app_name}></p>
<{config_load file = "app.conf" section = "db"}>
<p><{$smarty.config.dbname}></p>
<p><{$smarty.post.user_name}></p>
<p><{$smarty.get.page}></p>
<p><{$smarty.session.pass}></p>


</body>
</html>

tt.png

Correcting teacher:查無此人Correction time:2019-09-05 14:27:44
Teacher's summary:完成的不錯。php的框架多學幾款,對以后工作有幫助。繼續(xù)加油

Release Notes

Popular Entries