首先,非常感谢
我的问题是我有Page(indexStatic.php)有内容变量返回并影响一些头标签,如包含js文件但是当我启动文件时给出这样的消息: 我想访问indexStatic.php
中的displayControler.php变量<b>Fatal error</b>: Uncaught exception 'Exception' with message 'js doesn't exist in this class' in C:\webServer\htdocs\blabla\admin\AdminPanel\core\modelAbstract.php:25
Stack trace:
#0 C:\webServer\htdocs\blabla\admin\AdminPanel\static\indexStatic.php(2): ModelAbstract->__set('js', '<script src="re...')
#1 C:\webServer\htdocs\blabla\admin\AdminPanel\core\tools.php(14): include('C:\webServer\ht...')
#2 C:\webServer\htdocs\blabla\admin\AdminPanel\core\displayControler.php(33): tools->includeFile('/static/indexSt...')
#3 C:\webServer\htdocs\blabla\admin\AdminPanel\core\displayControler.php(28): displayControler->getContentHtml('/static/indexSt...')
#4 C:\webServer\htdocs\blabla\admin\AdminPanel\core\displayControler.php(18): displayControler->setUrlTofunc(NULL)
#5 C:\webServer\htdocs\blabla\admin\AdminPanel\index.php(17): displayControler->showHtml()
#6 {main}
thrown in <b>C:\webServer\htdocs\blabla\admin\AdminPanel\core\modelAbstract.php</b> on line <b>25</b><br />
indexStatic.php包含在displayControler.php中,让我们看看文件:
indexStatic.php文件:
<?php
$this->js ='<script src="resources/scripts/editablegrid-2.0.1.js"></script> ';
$this->js .='<script src="resources/scripts/jquery-1.7.2.min.js" ></script>';
$this->js.='<script src="resources/scripts/demo.js" ></script>';
return'<div class="content-box"><!-- Start Content Box -->
<script type="text/javascript">
window.onload = function() {
datagrid = new DatabaseGrid();
};
</script>
</div>';
?>
displayControler.php
class displayControler extends ModelAbstract
{
protected $js;
protected $tools;
protected $title;
protected $meta;
protected $content='';
protected $urls=array(
'main'=>'static/aboutStatic.php'
);
public function __construct(){
$this->setTitle(defaultVar::$static['title']);
}
public function showHtml(){
$this->setUrlTofunc(@$_GET['cont']);
include 'static/adminStatic.php';
}
public function setUrlTofunc($url){
$this->tools=new tools();
if(isset($url) and isset($this->urls[$url]) ){
$this->getContentHtml($this->urls[$url]);
}else{
$this->getContentHtml(defaultVar::$static['filePath']);
}
}
public function getContentHtml($url){
$catch = $this->tools->includeFile($url);
$this->setContent($catch);
}
}
和modelAbstract.php有:
abstract class ModelAbstract{
public function __call($name, $args){
$methodPrefix = substr($name, 0,3);
$methodProperty = strtolower($name[3]).substr($name,4);
switch ($methodPrefix){
case "set":
if (count($args) == 1)
$this->__set($methodProperty,$args[0]);
else
throw new \Exception("magic method only supports one argument");
break;
case "get":
return $this->__get($methodProperty);
break;
default:
throw new Exception("magic methods only supported for get and set");
}
}
public function __set($name,$value){
if (property_exists($this, $name))
$this->$name = $value;
else
throw new \Exception("$name doesn't exist in this class");
}
public function __get($name){
if (property_exists($this, $name))
return $this->$name;
else
throw new \Exception("$name doesn't exist in this class");
}
}
答案 0 :(得分:0)
$ js属性受到保护,因此您无法直接访问它。你在Model类中有魔法,它为你的属性制作了getter和setter。
这意味着它将通过魔术召唤。尝试使用$ this-&gt; setJs(“”)而不是$ this-&gt; js =“”。