How to extend controller in codeigniter?

by elise_daugherty , in category: PHP Frameworks , 3 months ago

How to extend controller in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 3 months ago

@elise_daugherty 

To extend a controller in CodeIgniter, follow these steps:

  1. Create a new controller file that will extend the base controller in the "application/controllers" directory within your CodeIgniter project.
  2. Define the new controller class in the file and make sure it extends the base controller class using the following syntax:
1
2
3
class New_Controller extends CI_Controller {
   //your controller code here
}


  1. Within the new controller class, you can now add your custom functions and properties as needed.
  2. Save the file.
  3. Now you can use the new controller in your CodeIgniter application by routing to it in your routes file or directly accessing it through the URL.


That's it! Your new controller should now be extending the base controller in CodeIgniter and ready to be used in your application.