• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to load extended core system classes from controller?

#1
[eluser]helloworld7[/eluser]
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.

http://ellislab.com/codeigniter/user-gui...asses.html

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.

#2
[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.

#3
[eluser]ccschmitz[/eluser]
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.

#4
[eluser]helloworld7[/eluser]
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

$this->input->get_mid();

or

$this->my_input->get_mid();

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.

#5
[eluser]ccschmitz[/eluser]
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:

Code:
$this->input->get_mid();


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.