Is this a good way to organize php?

Discussion in 'PHP' started by wwwbryan, Jul 28, 2009.

  1. #1
    I have an array on each page that calls a class:

    
    
    require_once("global.php");
    $globalarray = array(
    
    		'connection'=>$GLOBAL->getDBConnection(),
    		'heading_start'=>$GLOBAL->getHeading_start($title),
    		'container_start'=>$GLOBAL->getContainer_start(),
    Code (markup):
    and inside global is a class that has functions like this

    	function getHeading_start($title){
    		require_once("functions/heading_start.php");
    	}
    	function getContainer_start(){
    		require_once("functions/container_start.php");
    	}
    	function getTopbar(){
    		require_once("functions/topbar.php");
    	}
    	function getHeader(){
    		require_once("functions/header.php");
    	}
    	function getNavigation(){
    		require_once("functions/navigation.php");
    	}
    Code (markup):
    And it only requires the files when the page requests the function correct?
     
    wwwbryan, Jul 28, 2009 IP
  2. darren884

    darren884 Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What connection method are you using? Mysql_connect or something like PDO? Those require statements kind of defeat the whole purpose of classes, and it is not best practice to include them in classes like that.
     
    darren884, Jul 28, 2009 IP
  3. wwwbryan

    wwwbryan Well-Known Member

    Messages:
    181
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #3
    ok, Then what should I do?
     
    wwwbryan, Jul 29, 2009 IP