سؤال

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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top