PyroCMS 自定义库和 CI SuperObject
它应该很简单,但事实并非如此。
我有一个库希望使用其他库,但有些东西不活跃。
这两个库都位于 system/cms/libraries 中,因为据我所知,addons/shared_addons/libraries 完全无用,并且库需要自动加载(似乎 system/cms 本质上是系统/应用程序,但如果错误,请纠正我) )。顺便说一句:只是为了好玩,我在shared_addons/libaries中放置了一个库,只是为了看看我是否可以从模块中调用if;我不能。为什么它在那里?
库1
-需要数据库
-需要 lib2
Lib2
-need session
这就是发生的情况。控制器[模块]加载;调用 lib1,lib1 调用 lib2,抛出错误。 Lib1 将由所有模块控制器调用。 Lib2 使用之前设置的会话数据,并且仅由 lib1 调用。
在 lib2 中,我使用 $CI=get_instance() 来启用 CI 库(例如数据库、会话)。但是,我无法克服“致命错误:在非对象上调用成员函数 userdata()”; 它现在会被调用
//system/cms/libraries/lib2.php
$this->CI =& get_instance();
//$this->load->library('database'); == "can't find class database"
$ekeyLoc = $this->CI->session->userdata('ronery');
如果我在模块控制器中运行它,
,它会按预期工作。因此,在谷歌上搜索该错误,出现了很多“数据库未加载”的信息。只是为了确保,我尝试加载数据库,但是因为我,它找不到类“数据库”注意:数据库正在自动加载。
当您分配 CodeIgniter 超级对象时,我假设它正在抓取整个 jabloney,对吧?我是这么想的。但为了确保这一点,我决定尝试在模块/控制器中加载数据库类,结果是,因为我,找不到。
我尝试查看 PyroCMS 文档以找出任何欺骗行为,但没有太多,而且对我的情况没有任何帮助。
为什么我无法从模块控制器加载核心库?
为什么我无法将核心库加载到 system/cms/libraries 中的自定义库中?
为什么我分配的 CodeIgniter 超级对象不包含会话/数据库垃圾?
为什么我无法从 /addons/shared_addons/library 加载库?
为什么从模块控制器调用 $this->session->userdata()
可以工作,但不能从 system/cms/libraries 文件夹中的库调用,即使 CodeIgniter 超级对象已被调用分配?
谢谢。
两天后没有答案,我发现继续寻求帮助不可避免地会导致这个问题成为谷歌搜索结果的顶部,这既令人沮丧又搞笑。 FML。
It should be simple, but it's not.
I have a library that is hoping to use other libraries, but something ain't jiving.
Both libs live in system/cms/libraries because as far as I can tell, addons/shared_addons/libraries is utterly useless and the libraries need to be autoloaded (it seems that system/cms is essentially system/application but please correct me if wrong). An aside: just for kicks I put a library in shared_addons/libaries just to see if I could call if from a module; I couldn't. Why is it there?
Lib1
-needs db
-needs lib2
Lib2
-needs session
Here's what happens. Controller [module] loads; calls lib1 which calls lib2 which throws an error. Lib1 is to be called by all module controllers. Lib2 uses session data that is set earlier on and is only called by lib1.
In lib2 I use $CI=get_instance() to supposedly enable CI libs (e.g. database, session). However, I can't get past "Fatal error: Call to a member function userdata() on a non-object"; which is called by
//system/cms/libraries/lib2.php
$this->CI =& get_instance();
//$this->load->library('database'); == "can't find class database"
$ekeyLoc = $this->CI->session->userdata('ronery');
now if I run this in a module controller, it works as expected.
So googling that error, a lot of "db not loaded"'s come up. Just to make sure, I tried to load the database, but because eff me, it can't find class 'database' NB: database is being autoloaded.
When you assign CodeIgniter super object, I'm assuming it's grabbing the whole jabloney, right? I thought so. But to make sure, I decided to try and load the database class in a module/controller, which turns out, because eff me, couldn't be found.
I tried looking through the pyroCMS docs to find out about any trickery, but there ain't much, and none helpful to my situation.
Why can't I load a core library from a module controller?
Why can't I load a core library into a custom library in system/cms/libraries?
Why doesn't the CodeIgniter super object I assign contain session/db crap?
Why can't I load a library from /addons/shared_addons/library?
Why would a call to $this->session->userdata()
work from a module controller, but not from a library in the system/cms/libraries folder even though CodeIgniter super object has been assigned?
Thanks.
After 2 days with no answer, I find it both frustrating and hilarious that continuing to search for help inevitably leads to this question being the top google result. FML.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,
这不是有效的 CodeIgniter 代码,就像他们的文档所说的那样:
正如您已经指出的那样,尽管这是自动加载的,所以无论如何都不需要这样做。
为什么我无法从模块控制器加载核心库?
可以。
为什么我无法将核心库加载到 system/cms/libraries 中的自定义库中?
可以。
为什么我分配的 CodeIgniter 超级对象不包含会话/数据库垃圾?
它确实包含。
为什么我无法从 /addons/shared_addons/library 加载库?
这在 1.3.x 中是不可能的,但应该在 1.3.2 中修复,如果自 2.0 以来没有修复的话。
我不知道你在做什么,也不知道为什么会遇到这样的问题,但如果没有任何示例代码或你正在使用的 PyroCMS 版本的描述,我无法提供任何进一步的帮助。
如果您已经被困两天了,为什么还没有在我们的论坛上发帖呢?如果您在我们的论坛上发帖(我没有看到任何相关内容),您应该在这篇文章中添加一个链接到您的论坛主题,以帮助其他人回答问题。
这不是第一次有人被困在互联网上,但你表现得就像是这样。来吧,你知道这是如何运作的! :)
First things first:
That is not valid CodeIgniter code, like their documentation says it should be:
As you've already pointed out though this is autoloaded so there is no need to do that anyway.
Why can't I load a core library from a module controller?
You can.
Why can't I load a core library into a custom library in system/cms/libraries?
You can.
Why doesn't the CodeIgniter super object I assign contain session/db crap?
It does.
Why can't I load a library from /addons/shared_addons/library?
This was not possible in 1.3.x but should have been fixed in 1.3.2, if not has been fixed since in 2.0.
I do not know what you are doing or why you are having such problems, but without any example code or a description of what version of PyroCMS you are using I cannot help any further.
If you have been stuck for two days why have you not posted on our forums? If you HAVE posted on our forums (I didn't see anything about it) you should have put a link in this post to your forum thread to help other people answer the questions.
This is not the first time anyone has been stuck on the internet but you act like it is. Come on, you know how this works! :)