CodeIgniterCodeIgniterCodeIgniterFramework is a collection of instructions collected in a function and class with a function to facilitate the developer in the call without having to write the same program syntax over and over again. Source code will look cleaner and more structured.
Codeigniter is a php framework that is open source and certainly free for every use, The purpose behind the development of a framework to facilitate the programmer in building a web-based applications. The method used is MVC (Model, View, Controller). Webserver Packages (AppServ, XAMPP, EasyPHP, WAMP, etc) & Code Igniter Codeigniter (CI) is a PHP framework, aimed at people who want to build websites using PHP. Using a view-controller-model architecture that separates the logic and display sections of the program, CI is quite "fun" to use. Not difficult especially you have mastered the basic principles of OOP in PHP.
The concept that separates every major component into 3 MVC components is
Database is a set of data that has been arranged in such a way with the provisions or certain rules that are mutually related between several classes and components so as to facilitate the user in managing it also makes it easier to obtain information. In addition, those that define the database as a collection of interconnected files, tables, or archives stored in electronic media. Some of the benefits of the database is one of them is the database has the ability in selecting data to become a group that sorted quickly. This is what ultimately can produce the information needed quickly too.
localhost/phpmyadmin. Create a new database name to your liking, click new at the right corner of the phpmyadmin view.CREATE TABLE IF NOT EXISTS tb_book
(id_book varchar (10) NOT NULL,
title_book varchar (50) DEFAULT NULL,
stock_book year (4) DEFAULT NULL,
PRIMARY KEY (id_book ))
ENGINE = MyISAM DEFAULT CHARSET = latin1;
Here is a little analysis of the three SQL commands "create table" before the following is an explanation of the attributes - supporting attributes that follow the main command is :
Not Null is a field property that provides a condition for the field to be null or non-existent.
Auto_increment is a special field property for Primary Key that causes the field to have the ability to increase automatically continuously as the number of data stored in the table increases.
Default Null is a field property that gives a condition to the field may be null or can not be entered.
Primary Key is a field that specifically becomes a priority or identifies each record line contained in a table.
Key is a field that becomes a reference search data in a database table, where the field is also stored in the database index so that easier search.
Engine is a table property that defines the type of storage used to store data for each table.
Default Charset is a character type that is configured against the table.
INSERT INTO `tb_book`
(`id_book`, `Judul_book`, `Stok_book`)
VALUES ('14', 'BOLA.net', '2008'), ('22', 'Travelling', '2010');
<?php
class Test_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function cariOrang()
{
$cari = $this->input->GET('cari', TRUE);
$data = $this->db->query("SELECT * from dborang where Name like '%$cari%' ");
return $data->result();
}
}
class Test_model extends CI_Model
to serves classify the Test_Model class based on CI_Model
The construction method
is a function of contruct that will first be executed during operation.
$this->load->database();
To explain that we load a database file
public function cariOrang()
to declare a class function
$cari = $this->input->GET('cari', TRUE);
a boolean value as the second parameter
$data = $this->db->query("SELECT * from dborang where Name like '%$cari%' ");
to call the database with the selection of queries and search by name
return $data->result();
The value is returned using an optional return statement. If the return is omitted then the NULL value will be returned.
<?php
class Test extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper("url");
$this->load->model('Test_model');
}
public function cari()
{
$this->load->view('search');
}
public function hasil()
{
$data2['cari'] = $this->Test_model->cariTest();
$this->load->view('result', $data2);
}
}
parent::__construct();
serves to prepare the needs of the 'parent' class first, for example the car class. car class requires a brand name or type.
$this->load->helper("url");
Performing loading on every controller that will use helper, Helper also serves to help developers build applications more quickly and efficiently.
$data2['cari'] = $this->Test_model->cariTest();
is the program code in hasil function to declare the Test_model object in the search operation
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pencarian dengan CodeIgniter 3 » </title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h3>Pencarian</h3
> <hr>
<form action="" action="GET">
<div class="form-group">
<label for="cari">data yang dicari</label>
<input type="text" class="form-control" id="cari" name="cari" placeholder="cari">
</div>
<input class="btn btn-primary" type="submit" value="Cari">
</form>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pencarian dengan CodeIgniter 3 » Jaranguda.com</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h3>Hasil Pencarian</h3>
<hr>
<?php
if(count($cari)>0)
{
foreach ($cari as $data) {
echo $data->Name . " => " . $data->Country ."
";
}
}
else
{
echo "Data tidak ditemukan";
}
?>
</div>
</body>
</html>
localhost/CodeIgniter/index.php