1) Download the latest version of CodeIgniter.
2) Extract it and paste the extracted folder at the ‘htcdocs’ directory. In my scenario, I am using XAMPP 1.8.1, so I will paste it on the same directory. Also, you can rename the folder E.g. CI.
3) Take a look first at your config files and made some few modifications.
autoload.php
$autoload['libraries'] = array('database');
$autoload['helper'] = array('url');
config.php
$config['base_url'] = 'your localhost url';
in my case:
$config['base_url'] = 'http://localhost/CI/index.php/'; // your current URL on the address bar when displaying the welcome_message
$config['index_page'] = 'index.php'; // page where you want your viewers are redirected when they type in your website name
E.g. base_url — http://www.example.com/
index_page — index.php or straight ahead to news.php, it’s up to you
routes.php
$route['default_controller'] = 'site' // your controller's method, originally "welcome" to display welcome message
I set “site” as the default controller
database.php
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = '[your database]'; // e.g. CI_series
$db['default']['dbdriver'] = 'mysql';
TIP: Username as a default would be root if you don’t have any permissions for accessing the database yet. Also, leave password blank for now.
4) Start working with the Controllers
Controllers are the heart of your application, as they determine how HTTP requests should be handled. A Controller is simply a class file that is named in a way that can be associated with a URI.
E.g.
http://www.example.com/index.php/blog/
In the above example, CodeIgniter would attempt to find a controller named blog.php and load it.
When a controller’s name matches the first segment of a URI, it will be loaded.
– Reference
Now, let’s type the code for our controller.
<?php
class Site extends CI_Controller
{
function index()
{
$this->load->view('home.php');
}
}
?>
Basically, this will just load our view/page called home
* What is load?
Loader, as the name suggests, is used to load elements. These elements can be libraries (classes) View files, Helpers, Models, or your own files. (ref)
This code snippet would let you display the page, home.php. Also since, you’re calling home.php, you must have this page under the views folder. Create your home.php, write anything you would like to display as a test for our first run and save it.
This code snippet would let you display the page, home.php. Also since, you’re calling home.php, you must have this page under the views folder. Create your home.php, write anything you would like to display as a test for our first run and save it.
home.php
<p>
My view has been loaded. Welcome!
</p>
Also, save our controller under the controllers folder, file name should be the same as your class name. In this case, it should be saved as site.php.
The first run:
htaccess
. it could help – Coryden