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