- Download GroceryCrud image crud di grocerycrud.com/imgae-crud
- Extract hasil downloadnya, lalu copy and replace pada folder codeigniter
- Buka phpMyAdmin di http://localhost/phpmyadmin/
- Buat database baru, contoh : db_image
- lalu klik pada menu SQL
- Pastekan examples_database.sql kedalam SQL hasilnya akan seperti berikut :
- Selanjutna konfigurasi database db_image dengan codeigniter
- Buka file database.php di xampp\htdocs\ImageCrud\application\config
- isi username dengan root dan database dengan db_image
- Buat controller di xampp\htdocs\application\controllers, Sebagai contoh : sibobi.php
- ketikkan kode berikut :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class sibobi 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('v_image.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);
}
}
- Selanjutnya buat v_image.php di xampp\htdocs\application\views, lalu ketikkan kode berikut<!DOCTYPE html><html><head><meta charset="utf-8" /><?phpforeach($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><div><a href='<?php echo site_url('sibobi/example1')?>'>Example 1 - Simple</a> |<a href='<?php echo site_url('sibobi/example2')?>'>Example 2 - Ordering</a> |<a href='<?php echo site_url('sibobi/example3/22')?>'>Example 3 - With group id</a> |<a href='<?php echo site_url('sibobi/example4')?>'>Example 4 - Images with title</a> |<a href='<?php echo site_url('sibobi/simple_photo_gallery')?>'>Simple Photo Gallery</a></div><div style='height:20px;'></div><div><?php echo $output; ?></div></body></html>
- Selanjutnya coba jalankan di browser dengan mengetikkan
http://localhost/codeigniter/index.php/sibobi - Jika berhasil akan seperti gambar di bawah ini
No comments:
Post a Comment