无对象的 Codeigniter 设计
似乎 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一种方法可以多次调用一个对象:
CodeIgniter 用户指南解释得很好。第三个参数 alc 将是您现在用来调用该对象与另一个对象的指令的参数,我必须自己这样做几次。
我不会执行 require 路由,因为 CI 可以很好地自行处理所有这些对象调用。
there is so a way to call an object more than once:
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.
您仍然可以实例化多个对象,只是不通过 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()
orinclude()
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.