Unable to load library when extending a core library |
[eluser]musonic[/eluser]
I've encountered a very strange problem. Firstly, I should point out that I'm using CI 2.0. I'm extending the Input class by creating a MY_Input class and placing it in my application/core folder. So far so good. The problem arises when I try and load a library that is in my application/libraries folder to use some additional functionality. I've tried the normal Code: $this->load->library('csrf'); Code: $this->csrf->someMethod(); Code: Undefined property: MY_Input::$load So, I try and get a CI instance and try it that way. Unfortunately, I simply get: Code: Fatal error: Call to undefined function get_instance() Code: $this->csrf =& load_class('csrf'); Code: $this->csrf Could someone please help me work out what's going on? I'm wasting a lot of time on something that should just work!!!
[eluser]musonic[/eluser]
Code: class MY_Input extends CI_Input { I've basically just copied the _sanitize_globals function to change the way it handles csrf. I've been having problems with the csrf security in CI 2.0 because it fails if the form you are submitting fails validation tests and is then resubmitted. I'm trying to incorporate the way that csrf is handled in pyroCMS into the input class rather than the form_validation class which is how pyroCMS does it.
[eluser]WanWizard[/eluser]
Can you please enclose the code in [ code ] tags? This is quite unreadable. After that, change 'contruct' to 'construct', and things will work again...
[eluser]musonic[/eluser]
Apologies for formatting. I've now edited. Also, thanks for pointing out the typo. However, unfortunately it hasn't solved the problem. From my log I can see that the function _validate_function() is being called and it is in this function that I try to load the library. The result is that I'm still getting an undefined property error: Code: Fatal error: Call to a member function library() on a non-object
[eluser]musonic[/eluser]
So I've been doing more digging... I tried loading the library using the function =& load_class() and passing it the correct parameters for it to find the file. This function is in the common.php class in the system/core folder. Unfortunately, although that does load the library file, it brings with it another problem. Because the input class (which now includes the csrf library class) loads before the Base5 class it now can't use the function =& get_instance() because that function is part of the Base5 class. To explain further, the csrf library class uses functions from the native CI session class. This is why we need a CI instance in the csrf library class. I can't think of a way around this problem. Hopefully someone else can!
[eluser]InsiteFX[/eluser]
The library is pre-loaded buy the system! InsiteFX
[eluser]pickupman[/eluser]
You mentioned it, but it is not shown in your code where you have add the CI superobject. Code: class MY_Input extends CI_Input {
[eluser]musonic[/eluser]
@InsiteFX - I assume you mean that the Input class is auto-loaded. That isn't the issue I'm having. I'm trying to load another library within the Input class. @pickupman - in the example code I posted, I don't use the superobject. It is currently loaded within the csrf library I'm trying to load. I have tried to use the superobject in order to try to load the csrf library but as I tried to explain in my previous post because the Input class is loaded before the Base5 class the method get_instance() does not yet exist. This is why the code you suggest doesn't work.
[eluser]pickupman[/eluser]
Applying syntax shown from the standard Input class, you should use: Code: $csrf =& load_class('csrf'); //May need to be load_class('Csrf'); This ends up being standard PHP OOP syntax. |
Welcome Guest, Not a member yet? Register Sign In |