无对象的 Codeigniter 设计

发布于 2024-12-10 18:56:00 字数 129 浏览 0 评论 0原文

似乎 codeigniter 只允许一个库的一个实例,我无法像通常那样设计一种包含包含相应详细信息数组的对象的解决方案。我正在考虑仅进行 AJAX 调用,以从视图中进行其他查询,以用相应的详细信息填充将要的对象。有人有更优雅的解决方案的想法吗?

Seems codeigniter only allows one instance of a library I can't design a solution with objects holding arrays of corresponding details as I usually would. I'm considering just doing AJAX calls to make additional queries from the view to fill the would be objects with their corresponding details. Does anyone have ideas for a more elegant solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

峩卟喜欢 2024-12-17 18:56:00

有一种方法可以多次调用一个对象:

$this->load->library('someclass', $params, 'alc');

CodeIgniter 用户指南解释得很好。第三个参数 alc 将是您现在用来调用该对象与另一个对象的指令的参数,我必须自己这样做几次。

我不会执行 require 路由,因为 CI 可以很好地自行处理所有这些对象调用。

there is so a way to call an object more than once:

$this->load->library('someclass', $params, 'alc');

the CodeIgniter User Guide explains that very well. the third parameter alc will be what you now use to call that object injunction with the other, I have to do this myself a few times.

i wouldn't do the require route as CI does a nice job of handling all those objects calls on its own.

屋檐 2024-12-17 18:56:00

您仍然可以实例化多个对象,只是不通过 codeigniter $this 超类。您可以简单地使用 require()include() 手动包含所需的库文件,并使用 $object = new MyClass();

然后,您可以使用 $this->load->view('viewname', array('object', $object )); 传递您创建的任何对象到视图;但要注意对象(类以这种方式传递到视图时,变量)将转换为数组元素。因此,在传递到视图之前,您仍然可以像在任何其他应用程序中一样将它们作为对象进行操作。

You can still instantiate multiple objects just not through the codeigniter $this super class. You can simply include the libray file you need manually using require() or include() for example and use $object = new MyClass();

You can then pass any objects you make to the view using $this->load->view('viewname', array('object', $object )); but beware objects (class variables) are converted to array elements when passed to the view in this way. So you can still manipulate them as objects before passing to the view as you would in any other application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文