//設置權限 chown nginx:nginx "4個目錄"; chmod 770 "4個目錄";
<?php define('SMARTY_DIR','/usr/local/lib/smartyLibs/');//定義lib路徑 require_once(SMARTY_DIR.'Smarty.class.php');//引用Smarty庫 $smarty=new Smarty();//建立Smarty define('SMARTY_SITE','/var/www/html/site_A/');//定義網站路徑 $smarty->setTemplateDir(SMARTY_SITE.'templates'); $smarty->setCompileDir(SMARTY_SITE.'templates_c'); $smarty->setConfigDir(SMARTY_SITE.'configs'); $smarty->setCacheDir(SMARTY_SITE.'cache'); $smarty->left_delimiter='{{'; $smarty->right_delimiter='}}'; $smarty->caching=false;//是否使用緩存 //$smarty->testInstall();//調試用,顯示4個目錄可讀寫狀態 ?>
<?php include('./smarty.ini.php');//引用smarty.ini.php配置文件 $name='YangGe123';//自定義變量 $smarty->assign('name',$name);//將變量賦予smarty值'name' $smarty->display('index.tpl');//在templates中引用對應的模板 ?>
<html>
<head></head>
<body>
<h1>{$name}</h1>
</body>
</html>
擴展知識:php
調試php,讓服務器顯示php錯誤信息:html
修改php.ini文件,將 display_error = off 改成 onnginx
重啓php服務緩存
service php-fpm restart服務器