How to extend controller in codeigniter?

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

How to extend controller in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 9 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.

Related Threads:

How to use model function result in controller by codeigniter?
How to get controller name in Codeigniter?
How to get post data in Codeigniter controller?
How to read json file inside codeigniter controller?
How to redirect from view to controller in codeigniter?
How to pass a variable from model to controller in codeigniter?