Hello World in CodeIgniter 2.1.0.
Steps:
1. Open http://codeigniter.com/downloads/
2. Download Current Version CodeIgniter 2.1.0.
3. Unzip CodeIgniter_2.1.0
File structure of CodeIgniter_2.1.0
- application
- system
- user_guide
- index
- licence
4. Create file called hello.php in your application/controllers folder & paste following code.
<?php
class Hello extends CI_Controller
{
function index()
{
echo 'Hello world!';
}
}
?>
5. Go to http://localhost/codeigniter/index.php/hello
6. You will get output Hello world
7. Update hello.php with following code
<?php
class Hello extends CI_Controller
{
function index()
{
echo 'Hello world!';
}
function test()
{
echo 'Second hello world!';
}
}
?>
8. Go to http://localhost/codeigniter/index.php/hello/test
9. You will get output 'Second hello world!
10. Using .htaccess and mod_rewrite you can remove the 'index.php' from url,
ie. http://localhost/codeigniter/hello or http://localhost/codeigniter/hello/test
11. Open wamp > bin > apache > apache2.2.8 > conf > httpd.conf
12. Search for LoadModule rewrite_module modules/mod_rewrite.so and uncomment it (Remove #)
#LoadModule rewrite_module modules/mod_rewrite.so to LoadModule rewrite_module modules/mod_rewrite.so
13. Save httpd.conf file & Stop All Services of WAMP & then Start All Services of WAMP
14. Create a “.htaccess” file in the root of CodeIgniter directory (where the application, system, user_guide directory resides), open the file using your favorite text editor, write down the following script and save it:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
15. Go to http://localhost/codeigniter/hello or http://localhost/codeigniter/hello/test