views:

31

answers:

2

Hi guys, I'm converting over a web-app to use the MVC structure of Zend Framework. I have a root.php include file that contains most of the database info, and some static variables that are used in the program. I'm not sure if some of this should be in the application.ini of in a model that is called by the init() function in a controller, or in the bootstrap or what?

Any help would be much appreciated!

root.php (include file at the top of every php page):

<?php

    /***
            //Configuration file
    */

    ## Site Configuration starts ##


    define("SITE_ROOT"      ,  dirname(__FILE__));


    define("SITE_URL"      ,  "http://localhost/monkeycalendarapp/monkeycalendarapp/public");
    define('DB_HOST', "localhost");
    define('DB_USER', "root");
    define('DB_PASS', "xxx");
    define('DB_NAME', "xxxxx");

    define("PROJECT_NAME"      ,  "Monkey Mind Manager (beta 2.2)"); //site title
    define("CALENDAR_WIDTH"      ,  "300"); //left mini calendar width
    define("CALENDAR_HEIGHT"    ,  "150"); //left mini calendar height

    $page_title = 'Event List';
  $stylesheet_name = 'style.css'; //default stylesheet


  define("SITE_URL_AJAX"    ,  SITE_URL . "/ajax-tooltip");
  define("JQUERY"    ,  SITE_URL . "/jquery-ui-1.7.2");

  $a_times    =  array("12:00","12:30","01:00","01:30","02:00","02:30","03:00","03:30","04:00","04:30","05:00","05:30","06:00","06:30","07:00","07:30","08:00","08:30","09:00","09:30","10:00","10:30","11:00","11:30");

  //PTLType Promotional timeline type
  $a_ptlType= array(1=>"Gigs","To-Do","Completed");

  $a_days      =  array("Su","Mo","Tu","We","Th","Fr","Sa");

  $a_timesMerd  =  array("12:00am","12:30am","01:00am","01:30am","02:00am","02:30am","03:00am","03:30am","04:00am","04:30am","05:00am","05:30am","06:00am","06:30am","07:00am","07:30am","08:00am","08:30am","09:00am","09:30am","10:00am","10:30am","11:00am","11:30am","12:00pm","12:30pm","01:00pm","01:30pm","02:00pm","02:30pm","03:00pm","03:30pm","04:00pm","04:30pm","05:00pm","05:30pm","06:00pm","06:30pm","07:00pm","07:30pm","08:00pm","08:30pm","09:00pm","09:30pm","10:00pm","10:30pm","11:00pm","11:30pm");

  //Setting stylesheet for this user.
  $AMPM=array("am"=>"am","pm"=>"pm");

  include(SITE_ROOT  .  "/includes/functions/general.php");
  include(SITE_ROOT  .  "/includes/db.php");

  session_start();
  if(isset($_SESSION['userData']['UserID']))  {
    $s_userID   =   $_SESSION['userData']['UserID'];
  }

  $stylesheet_name = stylesheet();

  ini_set('date.timezone', 'GMT');
  date_default_timezone_set('GMT');

  if($s_userID) {
    ini_set('date.timezone', $_SESSION['userData']['timezone']);
    date_default_timezone_set($_SESSION['userData']['timezone']);
  }

?>
A: 

Depends on how you are using the Framework. I don't see any ZF-related code in here so looks to me like you're rolling your own code and not using the Zend Framework Bootstrap and Application classes? Do you have an index.php file that all the requests are being routed to? I'd put these application-wide constants in there. If you are using the Application and Bootstrap classes, you should probably use .ini style config loading to put some of these parameters into an ini file, and maybe register them for use throughout your application with Zend_Registry.

Typeoneerror
@Typeoneerror The above code is the old code that I am re-writing for Zend Framework (to better learn the framework and OOP). I am using the standard ZF configuration (using Zend Tool) but right now most things are just in the public/ folder as I convert them. I do have the ZF index.php file there in public for all the routing. So that makes sense about constants going there.
Joel
A: 

Everything what needs configuration is a resource (you may use pre-defined ones, or write your own).

Resources may be configured in many ways, e.g.:

  • in application.ini
  • passing many config files to Zend Application in the index.php
  • configuring directly in the Bootstrap.

The best place for defines is index.php (include 'root.php'), indeed. However, you should reduce the number of global constants/variables to minimum (in this case, resource config files seem to be the best option).

takeshin