作者kalecgos0616 (.)
看板PHP
標題[請益] 函數中使用Smarty的tpl->assign
時間Wed Nov 3 10:59:01 2010
以下是我的程式碼:
<?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
1F:→ knives:global $tpl 11/03 11:31
2F:→ kalecgos0616:ok, thank you. 11/03 11:49
3F:推 water2924:$tp1這物件不存在阿 原po可以先多看幾篇Smarty教學文件 11/03 23:46
5F:推 maplecat:建議先檢查main 確定你是你是使用tpl 產生物件 11/04 10:41
6F:→ maplecat:且 我是沒有一次 使用兩個樣板的經驗 tpl進行的式樣版 11/04 10:42