来自模型内部的访问控制器方法 [英] Access controller method from inside a model

查看:77
本文介绍了来自模型内部的访问控制器方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从模型内部访问控制器方法?

解决方案

您不知道.

尽管从技术上讲是可能的,但是如果您认为自己需要,则表明您的应用程序设计存在缺陷.

Controller层是应用程序的基础,用于处理来自用户的请求,与Model层进行对话并将视图中的输出拼接在一起.您的模型层应该对控制器和视图不可见,但仅处理数据操作.这是对MVC模式的过度简化的解释(您可以在其他地方找到有关该资源的资源).

您的Codeigniter模型应可从任何控制器重用,而不依赖于它们.有许多解决方案可以解决您遇到的任何问题:您可以通过多种方式将数据传递到模型中,或者可以使用对模型方法的调用结果来在Controller中执行操作.

How do I access a controller method from inside a model?

解决方案

You don't.

Although it is technically possible, if you think that you need to, it suggests a flaw in your application's design.

The Controller layer is the backbone of you application and meant to handle requests from the user, talk to the Model layer, and stitch together the output in the View. Your Model layer should be blind to the Controller and View, but deal with data manipulation only. This is an over-simplified explanation of the MVC pattern (you can find resources for that elsewhere).

Your Codeigniter models should be reusable from any controller, and not dependent on them. There are many solutions to solve whatever problem it is that you have: You can pass data into a model in a number of ways, or you can use the result of a call to a model's method to perform an action in your Controller.

这篇关于来自模型内部的访问控制器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆