【发布时间】:2013-03-29 15:35:18
【问题描述】:
您好,我正在尝试制作我自己的简单模板系统之类的东西 我只是在学习类,所以我试图用类和对象来做。
如果我把它放在每个文档的顶部,它会起作用:
$template = new Includes('name', 'path');
$include = new Includes('name', 'path');
但感觉它不应该是必要的,而且它不是那么漂亮。
这就是我的代码现在的排列方式:
index.php:
<?php
require_once 'class_include.php';
$template->loadTemplate('body');
body.php:
<?php require_once 'class_include.php'; ?>
<head>
<?php $template->loadTemplate('head'); ?>
</head>
<body>
<?php
$template->loadTemplate('sidepanel');
$template->loadTemplate('content');
?>
</body>
class_include.php:
class Includes {
public function loadTemplate($name, $path = 'template'){
require_once "$path/$name.php";
}
public function loadInc($name, $path = 'inc'){
require_once '$path/$name' . '.php';
}
}
$template = new Includes('name', 'path');
$include = new Includes('name', 'path');
错误信息:
( ! ) 致命错误:在 C:\wamp\www\project\template\body.php 中的非对象上调用成员函数 loadTemplate()
( ! ) 注意:未定义变量:C:\wamp\www\project\template\body.php 中的模板
感谢您提供的任何帮助!
【问题讨论】:
标签: php class function templates require