Home > codeigniter > Hello world programme in Codeigniter

Hello world programme in Codeigniter

Basis

Like any other programming Here we will see how we can write a simple Hello world programme.
Create a controller file under controller folder called test.php.This name should match with the calls name.
The calss name should be started with capital letter whether the file name will be lower case.

Ex

<?php
class Test extends Controller {
function index()
{
echo ‘Hello World!’;
}
}
?>

Outline

—The class name here extended with parent Controller class .It is necessary to do because the local class will inherit all the properties and attributes of parent controller class available by CodeIgniter.
–index is the default function in this class.
–Then here is a echo statement to display
–Now go to browser and type example.com/index.php/test/ you will see the out put.
–According to the MVC approach the class name should start first and than the function name.If the function name remains blank that is called automatically by the class name in the browser.
–If we want our out put when typing only index.php in the browser,we have to change something in CodeIgniter
–Go to application->config->routes.php and change the default controller to that controller(test).
–Now if  you type example.com/index.php and reload the page it will open.

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment