我有一個用戶認證系統,我目前正在編寫。問題是,我不想爲每個我想要使用該類的頁面包含類x,y,z等。例如,這裏是索引頁:PHP - 避免每個頁面包含所有內容?
///////// I would like to not have to include all these files everytime////////
include_once '../privateFiles/includes/config/config.php';
include_once CLASSES.'\GeneratePage.php';
include_once DB.'\Db.php';
include_once HELPERS.'\HelperLibraryUser.php'; //calls on user class
//////////////////////////////////////////////////////////////////////////////
$html = new GeneratePage();
$helper = new HelperLibraryUser("username","password","email");
$html->addHeader('Home Page','');
$html->addBody('homePage',
'<p>This is the main body of the page</p>'.
$helper->getUserEmail().'<br/>'.
$helper->doesUserExists());
$html->addFooter("Copyright goes here");
echo $html->getPage();
正如你所看到的,有我需要包括每個頁面上的幾個文件,以及更多的類,我補充了更多的文件,我將不得不包括。我如何避免這種情況?
這會如何影響速度?我想它比指定類路徑的速度慢? – johnyboy 2011-04-02 07:09:30
噢,我通常把這個函數定義在一個常見的文件中,如Click提到... – awm 2011-04-02 07:09:38
謝謝你們:awn和Click Upvote!我會按建議做:) – johnyboy 2011-04-02 07:12:15