**Fatal error: Method Template::__toString() must not throw an exception, caught ParseError: syntax error, unexpected end of file in C:\xampp\htdocs\joblister\index.php on line 0**
我不知道哪里是错误的部分?你们能帮我吗?我一直在努力,但是没有办法解决。
<?php include_once 'config/init.php'; ?>
<?php
$job = new Job;
$template = new Template('templates/frontpage.php');
$template->title = 'Latest Jobs';
$template->jobs = $job->getAllJobs();
echo $template;
?>
答案 0 :(得分:-1)
这是因为您试图回显对象而不是字符串...
在模板类中,您需要实现魔术函数__toString()并定义应如何打印对象,或者您可以在类中使用自定义方法,例如getHtml()..该方法返回已构建的字符串并回显就是这样
echo $ template-> getHtml();