MVC 应用程序在 main 方法中运行
我正在创建一个个人 MVC 框架,并通过 google 搜索查看现有框架的代码并获取一些灵感。我注意到(但我可能弄错了),例如 CodeIgniter 的应用程序以某种方式包含在主方法中。 (由于在应用系统中使用了$this而被注意到)。
它是如何运作的?是否推荐(我认为拥有一些后台程序可以对我有很大帮助)?
I'm creating a personal MVC Framework and i googled around to see the code of existing ones and take some inspiration. I noticed (but i probably got it wrong), that for example CodeIgniter's Application are somehow included inside a main method. (Noticed because of the use of $this in the application system).
How does it works? Is it recommended (i think that having some background procedures could help me a lot)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Codeigniter 使用引导文件来包含并初始化所有必需的依赖项。大多数 MVC(例如 Zend 和 CI)都使用此引导程序文件。 Zend 实际上有引导程序中使用的 ini 文件。您可以通过 wiki 或 google 阅读有关 bootstrap 的更多信息。如果您自己编写,则大多数 MVC 主要基于带有 apache mod 重写的 URI 段(干净的 url),其中每个段都有自己的用途。您可以使用路由将页面定向到不同的 URI 结构等。例如 http:// domain.com/controller/method/some/other/segments... 这样,该 url 将加载“控制器”并调用该控制器中的“方法”。有趣的是使用 5.3 > 中的命名空间编写一个 php MVC。 ...做一些类似命名空间控制器的事情;保持事物井井有条且干净。由于类名冲突,我经常不得不使用某种命名约定,例如 Class Some 扩展 CI_Controller (将是我的控制器)和 Some_Model 扩展 CI_Model (将是我的模型)等。玩得开心!
Codeigniter uses a bootstrap file to include and initialise all required dependencies. Most MVC's such as Zend and CI use this bootstrap file. Zend actually has ini files that are used in the bootstrap procedure. You can read more information on the bootstrap by wiki or just google it. If you are writing your own, most MVC's are primarily based on the URI segments with apache mod rewrites (clean urls), where each segment has their own purpose. You use routes in order to direct pages to a different URI structure etc. Such as http://domain.com/controller/method/some/other/segments... So that url would load the "controller" and invoke the "method" in that controller. What would be interesting to do is write a php MVC utilising the namespaces as of 5.3 > ... Do something like namespace controller; to keep things organised and clean. I often have to use some kind of naming convention due to conflicts in class names such as Class Some extends CI_Controller (would be my controller) and Some_Model extends CI_Model (would be my models) etc. Have fun with it!