/    Sign up×
Bounties /Pin to ProfileBookmark

hi, how i can make one controler in codegniter 3

to post a answer
PHP

3 Replies

Davinci•003 auto-replyHi there! To create a controller in CodeIgniter 3, you'll need to create a new file in the controllers folder of your application. The file should be named after the controller you want to create, and should contain a class with the same name. The class should extend the CI_Controller class. Here's an example of what the code might look like in PHP:

class MyController extends CI_Controller {

public function index()
{
// Your code here
}

}


You can then add methods to the controller class to create the various functions you need. Hope this helps!

Was this helpful?

Copy linkTweet thisAlerts:
@samanrabieiauthorMar 15.2023 — this in safe
Copy linkTweet thisAlerts:
@abhishekMar 21.2023 — To create a controller in CodeIgniter 3, follow these steps:

1. Create a file with the name of the controller in the "application/controllers" directory. The file name should start with an uppercase letter, and the file extension should be ".php". For example, if you want to create a controller named "Welcome", create a file named "Welcome.php".

2. In the controller file, define a class with the same name as the file name. For example, if your controller file name is "Welcome.php", define a class named "Welcome" in it.

3. Extend the CI_Controller class. This makes your controller inherit all the methods and properties of the CI_Controller class. For example:

class Welcome extends CI_Controller {
// Controller code goes here
}


4. Define a function in the controller. This function will be called when the controller is accessed from the browser. For example:

class Welcome extends CI_Controller {
public function index() {
echo 'Hello, World!';
}
}


In this example, when the controller is accessed, it will print "Hello, World!" in the browser.

5. Save the file.

Now you have created a basic controller in CodeIgniter 3. You can access this controller by entering its URL in the browser. For example, if your controller name is "Welcome", the URL to access it will be "http://yourdomain.com/index.php/welcome". Note that "index.php" is the default entry point for CodeIgniter 3, but you can remove it using the .htaccess file if you want cleaner URLs.
×

Success!

Help @samanrabiei spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @junehugh,
tipped: article
amount: 500 SATS,

tipper: @buildinteractive,
tipped: article
amount: 1000 SATS,

tipper: @farhadmalegam,
tipped: article
amount: 1000 SATS,
)...