CMSMadeSimple 模块、PHP 和一般设计问题

发布于 2024-10-05 10:22:01 字数 1583 浏览 3 评论 0原文

我不知道是否可以在这里询问 CMSMadeSimple,但这里是。我见过其他 CMS 和框架问题。

我正在研究CMSMS的代码,以便我可以学习如何制作自己的CMS。我认为这确实是一个 php 和设计问题,但在这里:

http:// phpxref.com/xref/cmsmadesimple/nav.html?_functions/index.html

在 CMSModule 下,这是所有都必须继承的类,它们有以下代码:

class CMSModule
 479  {
 480      /**
 481       * ------------------------------------------------------------------
 482       * Initialization Functions and parameters
 483       * ------------------------------------------------------------------
 484       */
 485      var $cms;
 486      var $curlang;
 487      var $langhash;
 488      var $params;
.....
 509    function CMSModule()
 510      {
 511          global $gCms;
 512          $this->cms =& $gCms;
 513          $this->config =& $gCms->GetConfig();
 514  

最后一部分说什么?我不明白。特别是当它在类中处于较低位置时:

753      /**
 754       * Returns the cms->config object as a reference
 755       */
 756      function & GetConfig()
 757      {
 758          global $gCms;
 759          $config = &$gCms->GetConfig();
 760          return $config;
 761      }
 762  
 763      /**
 764       * Returns the cms->db object as a reference
 765       */
 766      function & GetDb()
 767      {
 768          global $gCms;
 769          $db = &$gCms->GetDb();
 770          return $db;
 771      }
 772  

这些看起来几乎什么都不做,或者他们永远自称......没有真正的数据库东西可以启动。

我希望通过参考所有的调用来了解这里的设计。

谢谢。

I don't know if I can ask about CMSMadeSimple here or not but here goes. I've seen other CMS and framework questions.

I am studying the code of CMSMS so that I can learn about making my own CMS. I think this is really a php and design question but here:

http://phpxref.com/xref/cmsmadesimple/nav.html?_functions/index.html

under CMSModule which is the class all have to inherit from they have this code:

class CMSModule
 479  {
 480      /**
 481       * ------------------------------------------------------------------
 482       * Initialization Functions and parameters
 483       * ------------------------------------------------------------------
 484       */
 485      var $cms;
 486      var $curlang;
 487      var $langhash;
 488      var $params;
.....
 509    function CMSModule()
 510      {
 511          global $gCms;
 512          $this->cms =& $gCms;
 513          $this->config =& $gCms->GetConfig();
 514  

What is that last part saying? I don't understand it. Especially when lower in the class it has:

753      /**
 754       * Returns the cms->config object as a reference
 755       */
 756      function & GetConfig()
 757      {
 758          global $gCms;
 759          $config = &$gCms->GetConfig();
 760          return $config;
 761      }
 762  
 763      /**
 764       * Returns the cms->db object as a reference
 765       */
 766      function & GetDb()
 767      {
 768          global $gCms;
 769          $db = &$gCms->GetDb();
 770          return $db;
 771      }
 772  

These look like they almost do nothing or that they keep calling themself forever....with no real db stuff to boot.

I am hoping to understand the design here with all the calls by reference.

Thank you.

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

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

发布评论

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

评论(1

一枫情书 2024-10-12 10:22:01

首先,CMSModule 类看起来像是使用包含来半派生自任何类型的对象 $gCms。它们看起来不像是同一类型的对象,否则确实会存在无限递归问题。看起来这段 PHP 代码几乎是在 v5 之前开发的并且继承性很好?可能有一个 CMS 类,但您正在阅读 CMSModule 类(如果这更有意义)。

详细来说,function & GetConfig 只是返回对全局对象 $gCms 上的 ->GetConfig() 调用所返回内容的引用。显然,这是为了实现一种 singleton 模式,以便始终使用一个主要配置回来了。对该配置和数据库的引用也保留(覆盖)到 CMSModule 对象中。这并不总是一个好主意,但在这种情况下确实有意义,因为它通常用于这种类型的应用程序,并且通常在 php 中使用(全局数据库对象等)。

To start with the CMSModule class looks like it is using containment to semi-derive from whatever the type of object $gCms is. It does NOT look like they're the same type of object, or there would indeed be infinite recursion issues. It almost looks like this PHP code was developed before v5 and good inheritance? There is probably a CMS class, but you're reading the CMSModule class, if that makes more sense.

To elaborate, the function & GetConfig is just returning a reference to what's returned by the ->GetConfig() call on the global object $gCms. Apparently, this is to implement a singleton pattern, so that there's one main configuration that's used and always returned. A reference to that config and db is also retained (overwritten) into the CMSModule object. This isn't always a great idea, but does make sense in this case, as it is used commonly for this type of an application, and in php in general (global db objects, etc).

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