Codeigniter,将变量从模型传递到控制器
Codeigniter 新手PHP。
我想从数据库中检索一位数据,将该一位数据转换为一个变量并将其传递给控制器并将该数据用作单个变量?例如,我可以使用控制器中的数据执行 if $string=$string 等操作。
如果有人可以提供模型和控制器的示例,我们将不胜感激。
New to Codeigniter & PHP.
I would like to retrieve a single bit data from a database, turn that single bit of data into a variable and pass it to the controller and use that data as a single variable? For example I could do a if $string=$string and so on, with the data in the controller.
If anyone could produce an example of a model and controller it would be gratefully appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这非常简单,直接取自 CodeIgniter 的文档,您绝对应该通读该文档(代码中的注释大多是我的):
控制器
模型
编辑
这是非常基本的东西,我强烈推荐阅读文档和浏览一些教程,但我会无论如何尝试提供帮助:
根据您下面的评论,您想要以下内容(诚然,这是相当模糊的):
请阅读数据库类文档。这实际上取决于您正在运行的特定查询以及您想要从中获取什么数据。根据上面的示例,在模型中的某些函数中,它可能看起来像这样(请记住,这完全是任意的,因为我不知道您的查询是什么样子或您想要什么数据):
This is pretty straightforward and taken right from CodeIgniter's documentation, which you should definitely read through (comments in the code are mostly mine):
The Controller
The Model
Edit
This is pretty basic stuff and I highly recommend simply reading through the documentation and walking through some tutorials, but I'll try to help anyway:
Based on your comment below, you want the following (which, admittedly, is pretty vague):
Please read over the Database class documentation. This really depends on the specific query you're running and what data you want from it. Based on the above example, it might look something like this in some function in your model (Keep in mind this is completely arbitrary as I have no idea what your query looks like or what data you want):