Halo, ini blog pertamaku disini aku mau ngasih tutorial cara membuat crud dengan menggunakan
Code igniter sama groucery crud. Pertama kalian donlot dulu bahan di bawah ini.
Setelah donlot bahan-bahannya kalian buka XAMPP dan jalankan apache dan mysql, pindahkan
folder CI ke htdocs dan tes CI nya. lalu kalian tes dengan memanggil CI nya di browser. sebelum
memanggil ubah nama file CI nya terlebih dahulu, bebas kalo aku pakai nama "base_url" lalu
panggil file CI nya ketik "localhost/base_url"
Ini adalah tampilan CI jika sukses dipanggil di browser.
Jika sudah sukses kalian buatlah databasenya seperti ini.
masuk ke database buat table dengan nama db_mulmed isinya seperti ini
:
ID char10 primarykey
FILENAME varchar50
FILETYPE varchar50
FILETEXT varchar50
FILEGROUP varchar50
FILECONTENT varchar50
FILEDESC varchar50
Setelah membuat database, sekarang buka file config.php di folder base_url dan isi confignya dengan
"localhost/(nama folder)base_url".
Lalu ubah isi database.php nya isikan username:root dan database : db_mulmed(database yang aku bikin barusan).
Buat file baru bernama Core.php di folder controller.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Core extends CI_Controller { function __construct() { parent::__construct(); $this->load->database(); } public function index() { echo "<h1>Welcome to the world of Codeigniter</h1>";//Just an example to ensure that we get into the function die(); } } /* End of file Core.php */ /* Location: ./application/controllers/Core.php */tes file tersebut "localhost/base_url/index.php/core.
kira-kira tampilannya akan seperti ini.
Selanjutnya edit Core.php dengan script ini.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Core extends CI_Controller {
function __construct()
{
parent::__construct();
/* Standard Libraries of codeigniter are required */
$this->load->database();
$this->load->helper('url');
/* ------------------ */
$this->load->library('grocery_CRUD');
}
public function index()
{
echo "<h1>Welcome to the world of Codeigniter</h1>";//Just an example to ensure that we get into the function
die();
}
public function db_mulmed()
{
$crud = new grocery_CRUD();
$crud->set_table('db_mulmed');
$output = $this->grocery_crud->render();
echo "<pre>";
print_r($output);
echo "</pre>";
die();
}
}
/* End of file Core.php */
/* Location: ./application/controllers/Core.php */
lalu coba panggil lagi "localhost/index.php/core/db_mulmed"
Jika tampilannya seperti ini jangan kaget ini sukses kok.
Selanjutnya buat file php baru di View dengan nama vcore.
masukkan script ini.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <?php foreach($css_files as $file): ?> <link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" /> <?php endforeach; ?> <?php foreach($js_files as $file): ?> <script src="<?php echo $file; ?>"></script> <?php endforeach; ?> <style type='text/css'> body { font-family: Arial; font-size: 14px; } a { color: blue; text-decoration: none; font-size: 14px; } a:hover { text-decoration: underline; } </style> </head> <body> <!-- Beginning header --> <div> <a href='<?php echo site_url('examples/offices_management')?>'>Offices</a> | <a href='<?php echo site_url('examples/employees_management')?>'>Employees</a> | <a href='<?php echo site_url('examples/customers_management')?>'>Customers</a> | <a href='<?php echo site_url('examples/orders_management')?>'>Orders</a> | <a href='<?php echo site_url('examples/products_management')?>'>Products</a> | <a href='<?php echo site_url('examples/film_management')?>'>Films</a> </div> <!-- End of header--> <div style='height:20px;'></div> <div> <?php echo $output; ?> </div> <!-- Beginning footer --> <div>Footer</div> <!-- End of Footer --> </body></html>Jika sudah memasukkan scriptnya coba update lagi file core.phpnya dengan script ini.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Core extends CI_Controller { function __construct() { parent::__construct(); /* Standard Libraries of codeigniter are required */ $this->load->database(); $this->load->helper('url'); /* ------------------ */ $this->load->library('grocery_CRUD'); } public function index() { echo "<h1>Welcome to the world of Codeigniter</h1>";//Just an example to ensure that we get into the function die(); } public function db_mulmed() { $crud = new grocery_CRUD(); $crud->set_table('db_mulmed'); $output = $crud->render(); $this->_example_output($output); } function _example_output($output = null) { $this->load->view('vcore.php',$output); } } /* End of file Core.php */Jika sudah di edit core.php nya
Panggil lagi url nya "localhost/index.php/core/db_mulmed"
Jika tampilan sudah seperti diatas berarti sudah selesai.
Makasih udah mau ngikutin tutorial ini sampai selesai :)
Comments
Post a Comment