Zend Framework - 对于 MVC,这个 root.php 文件应该放在哪里?

发布于 2024-09-05 08:03:26 字数 2519 浏览 6 评论 0原文

我正在通过网络应用程序进行转换以使用 Zend Framework 的 MVC 结构。我有一个 root.php 包含文件,其中包含大部分数据库信息以及程序中使用的一些静态变量。我不确定其中一些内容是否应该位于由控制器中的 init() 函数调用的模型的 application.ini 中,或者位于引导程序中还是什么?

任何帮助将不胜感激!

root.php(包含每个 php 页面顶部的文件):

<?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']);
  }

?>

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']);
  }

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不醒的梦 2024-09-12 08:03:26

需要配置的所有内容都是资源(您可以使用 预定义的,或编写您自己的)。

资源可以通过多种方式配置,例如:

  • 在 application.ini 中将
  • 许多配置文件传递给 Zend Application,在 index.php 中
  • 直接在 Bootstrap 中配置。

事实上,定义的最佳位置是index.php(include 'root.php')。但是,您应该将全局常量/变量的数量减少到最少(在这种情况下,资源配置文件似乎是最佳选择)。

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).

海螺姑娘 2024-09-12 08:03:26

取决于您如何使用该框架。我在这里没有看到任何与 ZF 相关的代码,所以在我看来,您正在滚动自己的代码,而不是使用 Zend Framework Bootstrap 和 Application 类?您是否有所有请求都路由到的index.php 文件?我将这些应用程序范围的常量放在那里。如果您使用Application和Bootstrap类,您可能应该使用 .ini 样式配置加载将其中一些参数放入 ini 文件中,并且可能使用 Zend_Registry 注册它们以便在整个应用程序中使用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文