如何在 codeIgniter 模型中使用 $this 引用控制器
我正在使用 CodeIgniter,在我的一个模型中,我想引用在 $this->load->model
和 中使用的
,而不是引用对象本身的$this
>$this->load->view$this
。
是否可以?
谢谢,
勒米安特
I am using CodeIgniter, and in one of my models I would like to refer the $this
which is used in $this->load->model
and $this->load->view
, instead of the $this
which refers to the object itself.
Is it possible?
Thanks,
Lemiant
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将无法使用
$this
来引用除模型对象本身之外的任何内容,这意味着您将无法执行$this = ...
操作。但是您可以使用以下函数获取控制器实例:
正如 aularon 提醒的那样,如果您的应用程序设计为您必须从模型访问控制器,那么也许您可能需要重新考虑其实现。
You won't be able to use
$this
to refer to anything but the model object itself, meaning you won't be able to do$this = ...
.But you can get the controller instance using the following function:
As aularon reminded though, if your application is designed such that you have to access your controller from a model, then perhaps you might want to rethink its implementation.