作者carlcarl (carl)
看板PHP
標題Re: [請益] smarty 前端html 問題
時間Wed Nov 16 12:24:20 2011
※ 引述《EJB (JAVA.net)》之銘言:
: 想請問一下
: 最近新網站要把php html code分開
: 按照以前所學到 我選擇用smarty 來架構
: 但目前遇到一個問題 網路上一直找不到方向
: 我想在前端網址部分呈現是 http://url/xxx.html?xxxxxx
: 但很多smarty 文章都是寫 http://url/xxx.php?xxxxx
: 主要我想把php都丟到後面邏輯運算就好 前端Jquery 和 html就好
: 想請問我該從哪邊改寫? 不知道我這樣表達清不清楚 thx
不太懂為什麼一定要指定副檔名為html?
smarty 一個網頁可以分為php和tpl(網頁顯示)兩個檔案
smarty的作法是去讀php
然後php處理完後 如果需要顯示的話 最後再加上call 對應tpl的function就好
所以一樣能夠將顯示和處理的邏輯分開
大致樣子可能像以下這樣
a.php
<?php
//處理東西
$tpl = new smarty
$tpl->assign('aa',aa)
$tpl->display(a.tpl)
?>
==================================
a.tpl
<html>
<head>
<title>a</title>
</head>
<body>
{if aa == 1}
aa
{/if}
</body>
</html>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.123.105.191
推 mervynW:php handler 指到 .html 不就的了 11/16 12:50
→ EJB:是上面要求 我只好想辦法做 11/16 13:08
→ EJB:不過謝謝 回答XD 11/16 13:09
推 shadowjohn:小改一下 httpd.conf 的設定即可 11/16 13:10
→ shadowjohn:AddType application/x-httpd-php .php .html .htm 11/16 13:11
推 shadowjohn:AddHandler application/x-httpd-php .php .htm 11/16 13:13
→ shadowjohn:上面那行可以放 .htaccess or php.ini 11/16 13:14