2
我有一个非常简单的类呼叫从包含的文件类的方法,可以设置类变量而不是调用方法/函数
if(!isset($_GET['page'])) {
$_GET['page'] = "home";
}
class be_site {
var $thelink;
public function get_static_content($page) {
$this->check_path($page);
} // end function
private function check_path($pathfile) {
if(file_exists($pathfile)) {
$b = 1;
include_once($pathfile);
} else {
$b = 2;
include_once('error_page.php');
}
}// End Function
public function selectedurl($subpage, $linkname){
if($subpage == $this->thelink) {
echo "<strong>" . $linkname . "</strong>";
} else {
echo $linkname;
}// End if
} // End function
} /// End site class
现在我在索引中创建新对象.PHP
include('connections/functions.php'); $site_object = new be_site;
在内容都是我
//get file
if(isset($_GET['subpage'])){
$site_object->get_static_content('content/' . $_GET['subpage'] . '.php');
}else {
$berkeley_object->get_static_content('content/' . $_GET['page'] . '.php');
}
好,所以一切正常。但是如果一个被包含的页面被调用,我会尝试使用我的其他方法来包装一个链接,如果根据$ _GET ['page']值选择它,则将其设为粗体。
例如
<ul>
<li><a href="index.php?page=team&subpage=about" target="_self" title="opens in same window" >
<?php $site_object->thelink = "about_us";
$site_object->selectedurl($_GET['subpage'],'about Our Website'); ?>
</a>
</li>...
等了各个环节。 现在可以在对象中设置变量但不调用该方法。我得到的错误
Fatal error: Call to undefined method stdClass::selectedurl()
很奇怪为什么我能够从一个包含文件中设置班上$ thelink变量,但不叫公共职能?
感谢
啊是的。 DOH!我忘了我不得不在全球范围内声明它,因为即使包含的文件现在已成为它的一部分,它仍然在范围之外。 – Nobby
抱歉忘了说谢谢:o) – Nobby