Monday, March 18, 2013

Hello World in Codeigniter

At first make a controler by writing the code below:
<?php
    class SayHello extends CI_Controller{ //inherits CI_Controller
        function __construct(){
            parent::__construct(); //calling the CI_Controller constructor
        }
       
        function show(){
            $this->load->view('Hello'); //loading view file Hello.php
        }
    }
?>


Give the file name SayHello.php and save it codeigniter\application\controllers\SayHello.php.

Then make a view by writing the code below:
<?php
    echo "Hello world"; //printing Hello world
?>


Give the file name Hello.php and save it codeigniter\application\views\Hello.php.

Then write http://localhost/codeigniter/index.php/SayHello/show/ into your browser and see the magic.  Here SayHello is your controller class name and show is that controler function name.

No comments:

Post a Comment