0

我收到无法重新声明类错误。这是导致错误的类文件

<?
class siteLoader{


public $view;
protected $page;
//vars for render head function
protected $arraySize;
protected $counter;

public function __construct(){}
//renders the view for the site
public function renderView($view){
    $this->view = $view;
    return "view/{$view}.view.php";
}
//renders the head part of the site
//public function renderHead($head){
public function renderHead($charset,$title,$description,$keywords,$applicationName,$css){
    //$this->head = $head;
    $this->charset = $charset;
    $this->title = $title;
    $this->description = $description;
    $this->keywords = $keywords;
    $this->applicationName = $applicationName;
    $this->css = $css;
    $arraySize = count($this->css, COUNT_RECURSIVE);
    $counter =0;
    echo '<head>
        <meta charset="'.$charset.'">
        <meta application-name="'.$applicationName.'">
        <meta keywords="'.$keywords.'">
        <meta description="'.$description.'">
        <title>'.$title.'</title>
    ';
    do{
        echo '<link type="text/css" rel="stylesheet" href="css/'.$this->css[$counter].'.css">';
        $counter++;
        }while($counter != $arraySize);
    echo '</head>';
    return 0;
}


}
?>

该错误仅在我调用 renderView() 函数时发生。下面是我调用类和函数的索引。

<!DOCTYPE html>
<html>
<?
if(!class_exists('siteLoader'))
{
require_once('/classes/html.class.php');
}

//$head = new html;
$html = new siteLoader;
$viewrender = new siteLoader;

$charset = "utf-8";
$title = "musicDB";
$description = "Not made yet";
$keywords = "music,DB,rock,Database,etc";
$applicationName = "Music DataBase";
$css = array('style');
$view = "main";
     $html->renderHead($charset,$title,$description,$keywords,$applicationName,$css);
include $viewrender->renderView($view);

?>
</html>

如上所示,我使用 require_once 并检查该类是否已加载。问题可能出在 renderView 函数中,因为当我不使用该函数时,一切正常。

4

1 回答 1

0

这一行包括 $viewrender->renderView($view); main.view.php 中的类名是什么 看看类名是不是siteloader

于 2015-11-24T09:09:50.307 回答