Welcome Guest, Not a member yet? Register   Sign In
How to load extended core system classes from controller?

I'm doing exactly from this page. I create my own MY_Input which extends CI_Input. I put MY_Input in application/core directory.


I just wonder how I can use it from my controller. I will use it in all controllers so I try to put it inside autoload.php

$autoload['libraries'] = array('My_Input');

But when I do this inside my controller it fails with this message.

An Error Was Encountered

Unable to load the requested class: my_input

How can I use MY_Input? Thanks.

[eluser]Mikhail Menshinskiy[/eluser]
You don't need to do anything. Your class loaded automatically.
Quote:Any functions in your class that are named identically to the functions in the parent class will be used instead of the native ones (this is known as "method overriding"). This allows you to substantially alter the CodeIgniter core.

Remember, you are extending the input library, not creating a new library called 'MY_Input'. You are trying to load a library that doesn't exist. You want to load the 'input' library, but it is already [email=http://ellislab.com/codeigniter/user-guide/libraries/input.html]initialized by CodeIgniter by default[/email] so there's no need to autoload it. If you remove 'My_Input' from being autoloaded you should be good to go.

But how do I use the new function from MY_Input inside my controller?

I still don't get it. CI_Input gets load automatically but not MY_Input right?

You mean I do this? get_mid() is a new function inside MY_Input




I was thinking about trying it but I want to make sure the correct way or there're multiple ways.

Please let me know. Thanks.

If you extended the class with the "MY_" prefix it is adding functionality to the existing core library so you would access the method like this:


Theme © iAndrew 2016 - Forum software by © MyBB