Monday, January 24, 2011

Firing Up CodeIgniter over XAMPP

 

So you want to develop web sites/applications using CodeIgniter framework on XAMPP? Here are the initial steps to make your first page work:

We will assume (1) you have successfully installed XAMPP at C:\XAMPP\ folder on your Windows machine. Otherwise, you have to read about it. (2) you have downloaded (and extracted)CodeIgniter.

STEP 1: Copy the extracted CodeIgniter files to at C:\XAMPP\htdocs\somewebfolder\

image

At this point you can open your favorite browser and navigate http://localhost/somewebfolder/ and you’ll see something like the below:

image

I know you want to see your own work! Let’s move to the next step.

STEP 2: Open \somewebfolder\system\application\config\config.php and change as follows:

FROM:

   $config['base_url'] = http://example.com/;

TO:

   $config['base_url'] = http://localhost/somewebfolder/;

STEP 3: Open \somewebfolder\system\application\config\routes.php and do the following change:

FROM:

   $route['default_controller'] = "welcome";

TO:

   $route['default_controller'] = "home";

Now, if you try to navigate http://localhost/somewebfolder/ you’ll be seing a 404 Page Not Found message. That’s fine! We just need to add home.php at the controllers folder and add another home_view.php file at the views folder.

Initial content of home.php can be

<?php

class Home extends Controller {

    function Home()
    {
        parent::Controller();   
    }
   
    function index()
    {
        $this->load->view('home_view');
    }
}

/* End of file home.php */
/* Location: ./system/application/controllers/home.php */

 

While home_view.php can have as follows

<html>
<head>
    <title>Home Page</title>
</head>
<body>
<h1>This is the home page!</h1>
</body>
</html>

There you have it! You have successfully created a home page in CodeIgniter over XAMPP.

9 comments:

  1. Thank you!!! Really appreciate this.

    ReplyDelete
  2. Thank you very much!!! Really appreciate this information.

    ReplyDelete
  3. Thank you very much!! Really appreciate this information.

    ReplyDelete
  4. Hi Shem,

    I have CodeIgniter 2.1.3 installed. I've done the following:

    -Copy application and system folder C:\xampp\htdocs\CI

    -Access C:\xampp\htdocs\CI\application\config\config.php and change the base URL to http://localhost/CI/ unlike instruction of this tutorial for the older version of CodeIgniter

    - Access C:\xampp\htdocs\CI\application\config\routes.php and change the $route['default_controller'] = "home"

    - Create home.php at C:\xampp\htdocs\CI\application\controllers

    - Create home_view.php at C:\xampp\htdocs\CI\application\views

    When I access http://localhost/CI/ I got

    Fatal error: Class 'Controller' not found in C:\xampp\htdocs\CI\application\controllers\home.php on line 3

    What can I do? I still do not understand how it works. The tutorials I follow left me in a dead end.

    ReplyDelete
    Replies
    1. Thank you for the message. Can you please share the contents of your home.php and home_view.php files?

      Delete
    2. load->view('home_view');
      }
      }

      /* End of file home.php */
      /* Location: ./application/controllers/home.php */

      Delete
  5. load->view('home_view');
    }
    }

    /* End of file home.php */
    /* Location: ./application/controllers/home.php */

    ReplyDelete
  6. Fatal error: Class 'Controller' not found in C:\xampp\htdocs\CI\application\controllers\home.php on line 3 how to resolve this plz tell????

    ReplyDelete