...

View Full Version : Separate Loading of Classes on index.php



egbakaet
01-31-2007, 02:34 AM
Well, the way I'm coding my site is based on whatever the result of $_GET["page"] is. Depending on what it is, I load a respective class to correspond, the source files, etc. Here is the code for the main section where everything is loaded:



<?php
switch($get_page) {
case "news":
require_once(KERNEL_PATH . "news/news.class.php");

$class =& new news($CONFIG);
$class->smarty->assign("IMAGE_URL", "images/headers/newsmain.gif");
$class->displaySection("", "global/header.tpl", "");

require_once(SOURCES_PATH . "public/news/news.index.php");
break;
case "login":
require_once(KERNEL_PATH . "global/login/login.class.php");

$class =& new login($CONFIG);
$class->smarty->assign("IMAGE_URL", "images/headers/loginmain.gif");
$class->displaySection("", "global/header.tpl", "");

require_once(SOURCES_PATH . "public/login/login.index.php");
break;
case "logout":
$class->logoutUser();
break;
case "register":
require_once(KERNEL_PATH . "global/login/register.class.php");

$class =& new register($CONFIG);
$class->smarty->assign("IMAGE_URL", "images/headers/loginmain.gif");
$class->displaySection("", "global/header.tpl", "");
require_once(SOURCES_PATH . "public/login/register.index.php");
break;
case "admin":
require_once(KERNEL_PATH . "admin/admin.class.php");

$class =& new admin($CONFIG);
$class->smarty->assign("IMAGE_URL", "images/headers/newsmain.gif");
$class->displaySection("", "global/header.tpl", "");

require_once(SOURCES_PATH . "admin/global/admin.index.php");
break;
default:
$class->smarty->assign("IMAGE_URL", "images/headers/errormain.gif");
$class->displaySection("", "global/header.tpl", "");
$class->setDispErrors("Required files for " . $get_page . " do not exist.", "Required Files Do Not Exist");
break;
}
?>


At the very top of the page, $class =& new main($CONFIG), where $CONFIG is the DB vars passed to each child class then to the parent class. I'm wondering, is there an easier way to accomplish this idea above? It loads very fast as it is (after smarty caches the pages upon first visiting). I want to be neat about how I code this however, so I need some help.

Calling all php gurus, addicts, and experts, mez a need some help lol. :thumbsup:

gunman
01-31-2007, 08:02 AM
Why didn't you try


function __autoload($class_name) {
require_once $class_name . '.php';
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum