Thursday, March 27, 2014

Use code igniter [Code ignigter install and create helloworld app.]

1. Install code igniter.

  • go to code igniter site and click download button.
http://ellislab.com/codeigniter
  • Installation Instruction.(Please refer to Code Igniter user guide.)
  1. Unzip the package.
  2. Upload the CodeIgniter folders and files to your server. Normally the index.php file will be at your root.
  3. Open the application/config/config.php file with a text editor and set your base URL. If you intend to use encryption or sessions, set your encryption key.
  4. If you intend to use a database, open the application/config/database.php file with a text editor and set your database settings.
2. create hello world php.
  • create helloworld.php file in application/controllers folder with these codes.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Helloworld extends CI_Controller {
    public function __construct() {
        parent::__construct();
    }

   function index()
   {
     echo 'Hello world!';
   }
   function test()
   {
      echo 'Second hello world!';
   }
}
3. create hello world php with view.
  • update helloworld.php file with these codes.
   function index()
   {
    // echo 'Hello world!';
       $this->load->view('helloview');
   }
  • create helloview.php file in application/view folder with these codes.
 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Hello World App</title>
</head>
<body>
    <h1>Hello World!</h1>
    <div >
        <p>My First CodeIgniter Application.
    </div>
</body>
</html>
4. passing parameters to view.

  • update helloworld.php file with these codes.
   function index()
   {
     // echo 'Hello world!';
  $data['message'] = 'Hello World!!!';
  $this->load->view('helloview', $data);
   }
  • update helloview.php file with these codes.
  <body>
    <h1><?php echo $message; ?></h1>



No comments:

Post a Comment