dongmei5168 2011-03-01 08:48
浏览 11
已采纳

MVC应用程序在main方法内运行

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

  • 写回答

1条回答 默认 最新

  • dongren2128 2011-04-10 17:43
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法