[請益] 函數中使用Smarty的tpl->assign
以下是我的程式碼:
<?php
require("main.php");
include("fun.php");
$a=123;
fun();
$tpl->assign("a", $a);
?>
fun.php
<?
function fun(){
$b=456;
$tpl->assign("b", $b);
}
我這樣寫,希望能在fun函數中能夠assign $b到網頁上,
但是產生這個錯誤:
Notice: Undefined variable: tpl in ...
Fatal error: Call to a member function assign() on a non-object in ...
在fun()裡面加入require("main.php");
又產生這錯誤:
Fatal error: Cannot redeclare class Smarty in ... /class/Smarty.class.php on
line 65
請問要怎麼樣在自訂的函數中使用Smarty把變數傳到網頁上呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.125.41.241
→
11/03 11:31, , 1F
11/03 11:31, 1F
→
11/03 11:49, , 2F
11/03 11:49, 2F
推
11/03 23:46, , 3F
11/03 23:46, 3F
→
11/03 23:51, , 4F
11/03 23:51, 4F
推
11/04 10:41, , 5F
11/04 10:41, 5F
→
11/04 10:42, , 6F
11/04 10:42, 6F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章