Setelah membahas tentang Codeigniter, kali ini saya akan membahas mengenai template/plugin yang bisa digunakan dalam CI, yaitu template Grocery CRUD.
- Download Grocery CRUD terlebih dulu
- Setelah mendownload dan mengekstrak file, copy folder application dan assets dari folder Grocery CRUD kemudian paste pada folder Codeigniter.
- Buatlah file baru pada folder controllers menggunakan text editor (saya menggunakan Sublime Text 3).Disini saya menamakan "pages.php" untuk file baru saya.
- Kemudian copy paste sintaks berikut ini:
- Untuk memastikan sintaks berhasil, bukalah http://localhost/nama_project/index.php/pages Apabila berhasil, maka browser akan menampilkan
- Selanjutnya, buatlah table pada database. Saya menggunakan phpmyadmin untuk membuat table yang saya beri nama "phonebook"
- Buka database.php pada folder config dan tambahkan settingan sesuai dengan database yang kalian buat.
- Kembali lagi ke file "pages.php" di controllers, tambahkan function phonebook seperti contoh berikut
- Sekarang, buatlah file baru pada folder views. Saya menamakan "our_template.php" untuk view tersebut.
- Terakhir, buka http://localhost/nama_project/index.php/pages/phonebook untuk memastikan project berhasil dikerjakan
1: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2: class Pages extends CI_Controller {
3: function __construct()
4: {
5: parent::__construct();
6: $this->load->database();
7: }
8: public function index()
9: {
10: echo "<h1>Welcome to the world of Codeigniter</h1>";//Just an example to ensure that we get into the function
11: die();
12: }
13: }
CREATE TABLE IF NOT EXISTS `phonebook` (
`PhonebookNumber` int(11) NOT NULL AUTO_INCREMENT,
`Nama` varchar(50) NOT NULL,
`Alamat` varchar(100) NOT NULL,
`HP` varchar(20) NOT NULL,
`Email` varchar(50) NOT NULL,
`Kelas` varchar(10) NOT NULL,
PRIMARY KEY (`PhonebookNumber`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
INSERT INTO `phonebook` (`PhonebookNumber`, `Nama`, `Alamat`, `HP`, `Email`, `Kelas`) VALUES
(1, 'Kania Amalia', 'Bintaro Jaya Sektor 9', '08128839283', 'kaniaamalia21@gmail.com', 'PWeb A'),
(2, 'Vinsensia Sipriana', 'Medan Sumatera Utara', '082199392039', 'vinsensiasip@gmail.com', 'PWeb A'),
(3, 'Aviananda DJ', 'Medang Lestari Tangerang', '081228382938', 'avianandadj@gmail.com', 'PWeb E'),
(4, 'Muhammad Hilman', 'Tanah Kusir Jakarta Selatan', '085628372687', 'hlmn.hg@gmail.com', 'PWeb B');
1: $db['default'] = array(
2: 'dsn' => '',
3: 'hostname' => 'localhost',
4: 'username' => 'root',
5: 'password' => '',
6: 'database' => 'grocerycrud',
7: 'dbdriver' => 'mysqli',
8: 'dbprefix' => '',
9: 'pconnect' => FALSE,
10: 'db_debug' => (ENVIRONMENT !== 'production'),
11: 'cache_on' => FALSE,
12: 'cachedir' => '',
13: 'char_set' => 'utf8',
14: 'dbcollat' => 'utf8_general_ci',
15: 'swap_pre' => '',
16: 'encrypt' => FALSE,
17: 'compress' => FALSE,
18: 'stricton' => FALSE,
19: 'failover' => array(),
20: 'save_queries' => TRUE
21: );
1: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2: class Pages extends CI_Controller {
3: function __construct()
4: {
5: parent::__construct();
6: /* Standard Libraries of codeigniter are required */
7: $this->load->database();
8: $this->load->helper('url');
9: /* ------------------ */
10: $this->load->library('grocery_CRUD');
11: }
12: public function index()
13: {
14: echo "<h1>Welcome to the world of Codeigniter</h1>";//Just an example to ensure that we get into the function
15: die();
16: }
17: public function phonebook()
18: {
19: $this->grocery_crud->set_table('phonebook');
20: $output = $this->grocery_crud->render();
21: echo "<pre>";
22: print_r($output);
23: echo "</pre>";
24: die();
25: }
26: }
1: <!DOCTYPE html>
2: <html lang="en">
3: <head>
4: <meta charset="utf-8" />
5: <?php
6: foreach($css_files as $file): ?>
7: <link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
8: <?php endforeach; ?>
9: <?php foreach($js_files as $file): ?>
10: <script src="<?php echo $file; ?>"></script>
11: <?php endforeach; ?>
12: <style type='text/css'>
13: body
14: {
15: font-family: Arial;
16: font-size: 14px;
17: }
18: a {
19: color: blue;
20: text-decoration: none;
21: font-size: 14px;
22: }
23: a:hover
24: {
25: text-decoration: underline;
26: }
27: </style>
28: </head>
29: <body>
30: <!-- Beginning header -->
31: <div>
32: <a href='<?php echo site_url('examples/offices_management')?>'>Nama</a> |
33: <a href='<?php echo site_url('examples/employees_management')?>'>Alamat</a> |
34: <a href='<?php echo site_url('examples/customers_management')?>'>HP</a> |
35: <a href='<?php echo site_url('examples/orders_management')?>'>Email</a> |
36: <a href='<?php echo site_url('examples/products_management')?>'>Kelas</a> |
37: </div>
38: <!-- End of header-->
39: <div style='height:20px;'></div>
40: <div>
41: <?php echo $output; ?>
42: </div>
43: <!-- Beginning footer -->
44: <div>Footer</div>
45: <!-- End of Footer -->
46: </body>
47: </html>
Komentar
Posting Komentar