Starting a new project in CodeIgniter, a powerful PHP framework, can be both exciting and daunting. To help you get started smoothly, this step-by-step guide will walk you through the process of setting up a new project in CodeIgniter.
First, download the latest version of CodeIgniter from the official website. Extract the downloaded file to your desired project location on your server.
Open application/config/config.php
and set the base URL. This is essential for CodeIgniter to know the root URL of your application.
1
|
$config['base_url'] = 'http://your-domain.com/'; |
In the application/config/database.php
file, configure your database settings.
1 2 3 4 5 6 7 8 9 10 |
$db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'your_username', 'password' => 'your_password', 'database' => 'your_database', 'dbdriver' => 'mysqli', 'dbprefix' => '', ... ); |
Adjust the autoload.php
file in the application/config
directory to autoload the libraries, helpers, and packages you will frequently use.
1 2 |
$autoload['libraries'] = array('database', 'session'); $autoload['helper'] = array('url', 'form'); |
To clean up your URLs by removing index.php
, you can follow this guide on removing index.php.
Ensure your site is secure by redirecting from HTTP to HTTPS. For details, see this article on HTTP to HTTPS redirection.
Create a new file named Welcome.php
in the application/controllers
directory with the following code:
1 2 3 4 5 6 7 8 |
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Welcome extends CI_Controller { public function index() { $this->load->view('welcome_message'); } } |
By following these steps, you will have a functional CodeIgniter project up and running in no time. Happy coding!