Grocery Crud adalah library open source yang digunakan untuk melakukan generate fitur CRUD (Create Read Update Delete) secara otomatis pada aplikasi berbasis web yang dibuat menggunakan framework CodeIgniter.
1. Langkah awal download Framework CodeIgninter nya di https://codeigniter.com
2. Selanjutnya download Function Image Crud yang merupakan bagian dari Library Grocery Crud di https://www.grocerycrud.com/image-crud
3. Lalu ekstrak file image-crud-0.6.zip di projek Codeigniter nya, lakukan replace untuk menimpa file.
4. Selanjutnya buat Database baru dengan dengan nama db_crud_image pada phpMyAdmin.
5. Buka file example_database.sql yang ada folder project CI dan copy semua perintah SQL nya.
6. Lalu paste kan semua perintah SQL pada database db_crud_image di phpMyAdmin dan tekan tombol Go untuk mengeksekusi kalimat SQL.
7. Konfigurasi database pada projek CodeIgniter nya, buka file database.php yang ada pada folder application/config/database.php.
8. Selanjutnya buat Controller baru pada projek Codeigniter nya di folder application/controllers, beri nama Controller nya dengan nama Rizky (atau nama lainnya) dan isikan dengan kode dibawah ini :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Rizky extends CI_Controller {
function __construct()
{
parent::__construct();
/* Standard Libraries */
$this->load->database();
/* ------------------ */ $this->load->helper('url'); //Just for the examples, this is not required thought for the library
$this->load->library('image_CRUD');
}
function _example_output($output = null)
{
$this->load->view('example.php',$output); }
function index()
{
$this->_example_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
} function example1()
{
$image_crud = new image_CRUD();
$image_crud->set_primary_key_field('id');
$image_crud->set_url_field('url');
$image_crud->set_table('example_1')
->set_image_path('assets/uploads');
$output = $image_crud->render();
$this->_example_output($output);
}
function example2()
{
$image_crud = new image_CRUD();
$image_crud->set_primary_key_field('id');
$image_crud->set_url_field('url');
$image_crud->set_table('example_2')
->set_ordering_field('priority')
->set_image_path('assets/uploads');
$output = $image_crud->render();
$this->_example_output($output);
}
function example3()
{
$image_crud = new image_CRUD();
$image_crud->set_primary_key_field('id');
$image_crud->set_url_field('url');
$image_crud->set_table('example_3')
->set_relation_field('category_id')
->set_ordering_field('priority')
->set_image_path('assets/uploads');
$output = $image_crud->render();
$this->_example_output($output);
}
function example4()
{
$image_crud = new image_CRUD();
$image_crud->set_primary_key_field('id');
$image_crud->set_url_field('url');
$image_crud->set_title_field('title');
$image_crud->set_table('example_4')
->set_ordering_field('priority')
->set_image_path('assets/uploads');
$output = $image_crud->render();
$this->_example_output($output);
}
function simple_photo_gallery()
{
$image_crud = new image_CRUD();
$image_crud->unset_upload();
$image_crud->unset_delete();
$image_crud->set_primary_key_field('id');
$image_crud->set_url_field('url');
$image_crud->set_table('example_4')
->set_image_path('assets/uploads');
$output = $image_crud->render();
$this->_example_output($output); }
}
class Rizky extends CI_Controller {
function __construct()
{
parent::__construct();
/* Standard Libraries */
$this->load->database();
/* ------------------ */ $this->load->helper('url'); //Just for the examples, this is not required thought for the library
$this->load->library('image_CRUD');
}
function _example_output($output = null)
{
$this->load->view('example.php',$output); }
function index()
{
$this->_example_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
} function example1()
{
$image_crud = new image_CRUD();
$image_crud->set_primary_key_field('id');
$image_crud->set_url_field('url');
$image_crud->set_table('example_1')
->set_image_path('assets/uploads');
$output = $image_crud->render();
$this->_example_output($output);
}
function example2()
{
$image_crud = new image_CRUD();
$image_crud->set_primary_key_field('id');
$image_crud->set_url_field('url');
$image_crud->set_table('example_2')
->set_ordering_field('priority')
->set_image_path('assets/uploads');
$output = $image_crud->render();
$this->_example_output($output);
}
function example3()
{
$image_crud = new image_CRUD();
$image_crud->set_primary_key_field('id');
$image_crud->set_url_field('url');
$image_crud->set_table('example_3')
->set_relation_field('category_id')
->set_ordering_field('priority')
->set_image_path('assets/uploads');
$output = $image_crud->render();
$this->_example_output($output);
}
function example4()
{
$image_crud = new image_CRUD();
$image_crud->set_primary_key_field('id');
$image_crud->set_url_field('url');
$image_crud->set_title_field('title');
$image_crud->set_table('example_4')
->set_ordering_field('priority')
->set_image_path('assets/uploads');
$output = $image_crud->render();
$this->_example_output($output);
}
function simple_photo_gallery()
{
$image_crud = new image_CRUD();
$image_crud->unset_upload();
$image_crud->unset_delete();
$image_crud->set_primary_key_field('id');
$image_crud->set_url_field('url');
$image_crud->set_table('example_4')
->set_image_path('assets/uploads');
$output = $image_crud->render();
$this->_example_output($output); }
}
9. Setelah membuat Controller selanjutnya jalankan project Codeigniter nya dengan mengakses url http://localhost/crud-image/index.php/Rizky.
10. Setelah itu coba setiap halaman nya seperti halaman Example 1 - Simple, Example 2 - Ordering, Example 3 - With group id, Example 4 - Images with title, Simple Photo Gallery.
0 komentar:
Posting Komentar