You have to build a file name application/core/MY_Input.php and declare your class with Class MY_Input extends CI_Input {}to extend the native input class in CodeIgniter.
To extend a class in CodeIgniter, you typically use the concept of inheritance. Here’s how you can extend a class in CodeIgniter:
- Create your custom class: First, you need to create your custom class that extends the CodeIgniter class you want to extend. You can create this class within the
application/core
directory.php// application/core/MY_Controller.php
class MY_Controller extends CI_Controller {
// Your custom code here
}
- Extend the CodeIgniter class: In your custom class, extend the CodeIgniter class you want to extend. For example, if you want to extend the default
CI_Controller
, you would extend it in your custom class as shown above. - Use your custom class: Once you’ve created your custom class, you can now use it just like you would use any other CodeIgniter class. Simply load it as you would with any other library or controller.
php
// Example of using your custom controller
class Welcome extends MY_Controller {
public function index() {
// Your controller logic here
}
}
By following this approach, your custom class will inherit all the properties and methods of the class you’ve extended, allowing you to customize its behavior while retaining the core functionality of the original class.