Getting CodeIgniter HelloWorld example to work


Question

Guys I'm a newbie to code igniter.. I do not understanding how to use this framework. Its just opening the user guide. Can anyone tell me the steps I need to follow to execute the "hello world" program on code igniter?

1
5
5/12/2014 1:06:23 AM

Make a file called hello.php in your system/application/controllers folder. In the file, put this code:

<?php
class Hello extends Controller
{
   function index()
   {
     echo 'Hello world!';
   }
}
?>

Then go to http://localhost/codeigniter/index.php/hello , and you should see the hello world. (You might've put it in a different directory than codeigniter, so change the url as needed).

Then you can change the code to:

<?php
class Hello extends Controller
{
   function index()
   {
     echo 'Hello world!';
   }

   function test()
   {
      echo 'Second hello world!';
   }
}
?>

and going to http://localhost/codeigniter/index.php/hello/test would run the 'test' function from the class.

Using .htaccess and mod_rewrite you can remove the 'index.php' from your url, so you would only visit http://localhost/codeigniter/hello or http://localhost/codeigniter/hello/test.

10
2/22/2009 5:00:52 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon