Because the message
function is a method of indexmessage
. This has nothing to do with Smarty, it's just basic OOP.
$index = new indexmessage();
$message = $index->message();
$smarty->assign("indexmessage",$message);
문제
I'm very new to php and smarty.
I'm trying to call a function but can't understand why it's undefined. Here is my code:
include 'header.php'; include 'template/footer.tpl'; class indexmessage{ function message(){ global $pdo; $query = $pdo->prepare("SELECT * FROM hovedside WHERE id = 1"); $query->execute; return fetchAll(); } } $smarty->assign('indexmessage', message()); $smarty->display('index.tpl');
What am I doing wrong?
해결책
Because the message
function is a method of indexmessage
. This has nothing to do with Smarty, it's just basic OOP.
$index = new indexmessage();
$message = $index->message();
$smarty->assign("indexmessage",$message);