Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Separate Loading of Classes on index.php

    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 Code:
    <?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.

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why didn't you try
    PHP Code:
    function __autoload($class_name) {
       require_once 
    $class_name '.php';

    If you can not find a decision, maybe you have to try to change a problem

    http://www.gunman.co.nr
    http://bglinux.org


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •