Skip to main content
PHP Blog

Back to all posts

How to Call Controller Method In Codeigniter?

Published on
4 min read
How to Call Controller Method In Codeigniter? image

Best CodeIgniter Method Calling Guides to Buy in October 2025

1 CodeIgniter 2 Cookbook

CodeIgniter 2 Cookbook

BUY & SAVE
$54.99
CodeIgniter 2 Cookbook
2 CodeIgniter: Learn By Coding

CodeIgniter: Learn By Coding

BUY & SAVE
$2.99
CodeIgniter: Learn By Coding
3 Pro CodeIgniter: Learn how to create professional web-applications with PHP.

Pro CodeIgniter: Learn how to create professional web-applications with PHP.

BUY & SAVE
$9.50
Pro CodeIgniter: Learn how to create professional web-applications with PHP.
4 CodeIgniter: Web Framework (PHP Book 1)

CodeIgniter: Web Framework (PHP Book 1)

BUY & SAVE
$1.00
CodeIgniter: Web Framework (PHP Book 1)
5 Auto Mileage & Expense Notebook – Vehicle Mileage Log, Miles Log Book to Track Over 400 Rides or Sessions, Track Odometer for Business Driving or Rideshare Apps – 5 x 8 Inches, 60 Pages (Pack of 1)

Auto Mileage & Expense Notebook – Vehicle Mileage Log, Miles Log Book to Track Over 400 Rides or Sessions, Track Odometer for Business Driving or Rideshare Apps – 5 x 8 Inches, 60 Pages (Pack of 1)

  • EFFORTLESSLY TRACK MILEAGE AND EXPENSES WITH OUR SIMPLE LOG FORMAT.
  • ENJOY 33% MORE PAGES THAN COMPETITORS FOR YEAR-ROUND TRACKING NEEDS.
  • DURABLE DESIGN ENSURES LONG-LASTING USE FOR ALL YOUR RECORDING TASKS.
BUY & SAVE
$8.99 $9.99
Save 10%
Auto Mileage & Expense Notebook – Vehicle Mileage Log, Miles Log Book to Track Over 400 Rides or Sessions, Track Odometer for Business Driving or Rideshare Apps – 5 x 8 Inches, 60 Pages (Pack of 1)
6 The Standards Real Book, C Version

The Standards Real Book, C Version

  • AFFORDABLE PRICES COMPARED TO NEW BOOKS FOR BUDGET-CONSCIOUS BUYERS.
  • ECO-FRIENDLY CHOICE SUPPORTING RECYCLING AND SUSTAINABILITY EFFORTS.
  • QUALITY ASSURANCE: EACH BOOK IS CHECKED FOR READABILITY AND CONDITION.
BUY & SAVE
$47.00
The Standards Real Book, C Version
7 BookFactory Inventory Log Book/Small Business Inventory Tracker/Tracking Register - Wire-O, 100 Pages, 8.5'' x 11'' (BUS-100-7CW-PP-(InventoryTracker)-BX)

BookFactory Inventory Log Book/Small Business Inventory Tracker/Tracking Register - Wire-O, 100 Pages, 8.5'' x 11'' (BUS-100-7CW-PP-(InventoryTracker)-BX)

  • SIMPLIFY INVENTORY TRACKING WITH ONE PAGE PER SKU FOR EASY USE!
  • PERFECT FOR SMALL BUSINESSES: BARS, PLANT SHOWS, AND MORE!
  • PROUDLY MADE IN THE USA BY A VETERAN-OWNED COMPANY!
BUY & SAVE
$17.99
BookFactory Inventory Log Book/Small Business Inventory Tracker/Tracking Register - Wire-O, 100 Pages, 8.5'' x 11'' (BUS-100-7CW-PP-(InventoryTracker)-BX)
8 PHP CodeIgniter

PHP CodeIgniter

BUY & SAVE
$21.09
PHP CodeIgniter
+
ONE MORE?

In CodeIgniter, you can call a controller method by creating an object of the controller class and then calling the desired method using the object. First, load the controller class file using the load function provided by CodeIgniter. Then, create an object of the controller class and call the desired method using the object. You can pass any parameters required by the method as arguments while calling it. By following these steps, you can call a controller method in CodeIgniter from anywhere in your application.

How to call a private method within a controller in CodeIgniter?

In CodeIgniter, private methods within a controller cannot be directly called from outside the class. Private methods are only accessible within the class where they are defined. Therefore, if you need to call a private method within the same controller, you can simply call it directly from another public or protected method within the same controller.

Here is an example of how you can call a private method within a CodeIgniter controller:

class ExampleController extends CI_Controller {

public function index() {
    // Call private method within the same controller
    $this->private\_method();
}

private function private\_method() {
    echo 'This is a private method';
}

}

In the above example, the private_method is called from the index method within the same controller. This is the correct way to call a private method within a CodeIgniter controller.

What is the significance of URI routing in calling a controller method in CodeIgniter?

In CodeIgniter, URI routing is important in calling a controller method because it determines how the URL structure is mapped to specific controller methods. By defining URI routes in the routes.php configuration file, developers can customize the URL structure and specify which controller method should handle specific requests.

This allows for cleaner and more readable URLs, as well as better organization of the application's code base. Additionally, URI routing can be used to create SEO-friendly URLs that are easier for search engines to index.

Overall, URI routing plays a crucial role in the routing and dispatching process in CodeIgniter, allowing developers to effectively handle incoming requests and direct them to the appropriate controller methods.

What is the difference between calling a controller method and a function in CodeIgniter?

In CodeIgniter, a controller method is a function defined within a controller class that is responsible for handling a specific request from the user and returning a response.

On the other hand, a function in CodeIgniter is a standalone piece of code that performs a specific task and can be called from anywhere in the application.

The main difference between calling a controller method and a function in CodeIgniter is that a controller method is typically called in response to a user's request, such as when a specific URL is accessed, while a function can be called programmatically within the application code to perform a specific task.

Additionally, controller methods often interact with views and models to process and display data, while functions are usually self-contained and perform a specific task without interacting with other components of the application.

How to create a custom URL for calling a controller method in CodeIgniter?

To create a custom URL for calling a controller method in CodeIgniter, you can use routing in the routes.php file located in the application/config folder.

Here is an example of how you can create a custom URL for calling a controller method:

  1. Open the routes.php file in your CodeIgniter application's config folder.
  2. Add a new route that maps the custom URL to the controller method. For example, if you want to create a custom URL "custom-url" that calls the "index" method in the "CustomController" controller, you can add the following code:

$route['custom-url'] = 'CustomController/index';

  1. Save the routes.php file.

Now, when you navigate to your CodeIgniter application using the custom URL "http://example.com/custom-url", it will call the "index" method in the "CustomController" controller.

Note: Make sure you have the necessary controller and method created in your application before setting up the custom URL.