简体   繁体   English

Codeigniter和MVC

[英]Codeigniter and MVC

I am about to ask a more general conceptual question as apposed to a coding issue. 我将要提出一个与编码问题有关的更笼统的概念性问题。 I have recently started using the codeigniter framework and am trying to learn the principles of MVC - so please be patient. 我最近开始使用codeigniter框架,正在尝试学习MVC的原理-请耐心等待。 I roughly accept this as a really simplistic way of looking at MVC. 我粗略地认为这是查看MVC的一种非常简单的方法。

  • Models - Core logic of the system that passes data from DB to the controller 模型-将数据从数据库传递到控制器的系统核心逻辑
  • Controller - Glue that holds the system together and allows data from the view to be passed to the model and vice versa 控制器-将系统结合在一起的胶水,允许将视图中的数据传递到模型,反之亦然
  • View - The view that a user should see within the browser - some form data will be firstly passed to the controller. 视图-用户应该在浏览器中看到的视图-一些表单数据将首先传递给控制器​​。

*But I was wondering more about the ability of the model. *但是我想知道更多关于模型的能力。 For example, can data from the database be pulled from the model and stored? 例如,是否可以从模型中提取并存储数据库中的数据? For example, could the model hold an array of names say that I have queried back from the database? 例如,模型是否可以容纳一个名称数组,说我已从数据库中查询回来? Could I then display these to the user 1 by 1 using a button to increment a pointer to point to the next name in the array for example. 然后,我可以使用按钮将指针逐个显示给用户1来增加指针,以指向例如数组中的下一个名称。 I apologize if this is a stupid question just trying to figure out how data from the db is handled within the model. 如果这是一个愚蠢的问题,我很抱歉,只是想弄清楚在模型中如何处理数据库中的数据。

can data from the database be pulled from the model and stored? 数据库中的数据可以从模型中提取并存储吗? for example could the model hold an array of names say that I have queried back from the database? 例如,模型是否可以容纳一个名称数组,说我已经从数据库中查询回来?

The purpose of the model is to represent the data/state of the application. 模型的目的是代表应用程序的数据/状态。 The implementation (data pulled and cached in a model object) doesn't matter. 实现(将数据提取并缓存在模型对象中)无关紧要。 The model is supposed to allow the view to show itself and allow the controller to modify itself. 该模型应该允许视图显示其自身,并允许控制器对其进行修改。 There should be no business logic in the model (that's what the controller is there for). 模型中应该没有业务逻辑(这就是控制器的用途)。 So, yes, the model can store data from a database. 因此,是的,该模型可以存储数据库中的数据。

could I then display these to the user 1 by 1 using a button to increment a pointer to point to the next name in the array for example 然后我可以使用按钮将指针递增到指向数组中的下一个名称的方式将这些显示给用户1比1。

The presentation logic, or how you display a model to the user is a responsibility of the view . 表示逻辑或如何向用户显示模型是视图的责任。 The model should allow the view to query the data, and then display it. 该模型应允许视图查询数据,然后显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM