Labels

Sunday, October 16, 2011

Getting Started Create a Website with CodeIgniter

CodeIgniter has a concept of MVC (Model View Controller) in the creation of websites. MVC concept has many maanfaat among others split between logic and presentation, thus making the website could be more structured. Models are typically used to query the database for example insert, update, delete or select. While the View is used to display the output of existing processes. Controller is used to connect between the Model and View. Controllers can also be used to validate input before the data entered into the database. Next let's start creating a simple application example showing the words "hello world".




<?php
class Helloworld extends Controller {
    function Helloworld()
    {
        parent::Controller();
        $this->load->model('helloworld_model');  
    }

    function index()
    {
        $data = $this->helloworld_model->data();
        $this->load->view('output',$data);
    }
}
?>



explanation:
Remember the naming class must use capital letters at the beginning.
The script $ this-> load-> model ('helloworld_model') is used to access files named helloworld_model model.
The script $ data = $ this-> helloworld_model-> data (); used to call the function data () that existed at helloworld_model. Function has a return value that was then in the capacity into the variable $ data.
The script $ this-> load-> view ('output', $ data); used to call the view that output is accompanied by a variable named $ data in it.

4.Buatlah a model file and name it helloworld_model.php and place it in a folder system / application / models. Fill the file is as follows:




<?php
class Helloworld_model extends Model {
    function Helloworld_model()
    {
        parent::Model();
    }

    function data()
    {
        $data['test'] = 'Hello World !!';
        return $data;
    }
}
?>

5.Make a view file and name it output.php and place it in a folder system / application / view. Fill the file is as follows:

<html>
<head>
<title>Hello World !!</title>
</head>
<body>
<h1><?=$test;?></h1>
</body>
</html>


6. Please access your browser eg http://localhost/CodeIgniter/

0 comments

Post a Comment