Showing posts with label groceryCRUD. Show all posts
Showing posts with label groceryCRUD. Show all posts

Sunday, January 5, 2014

Fungsi-fungsi lain di GroceryCRUD

- Set_relation( string $field_name , string  $related_table, string  $related_title_field  [, mixed $where [,
Contoh :
Function employees_management()
{
    $crud = new grocery_CRUD();
    $crud->set_theme('datatables');
    $crud->set_table('employees');
    $crud->display_as('officeCode','Office City');
    $crud->set_subject('Employee');
    $crud->set_relation('officeCode','offices','city');
    $output = $crud->render();
    $this->_example_output($output);
} 
 
- set_field_upload( string $field_name, string $upload_path) 
Contoh :
function employees_management()
{
    $crud = new grocery_CRUD();
    $crud->set_theme('datatables');
    $crud->set_table('employees');
    $crud->set_relation('officeCode','offices','city');
    $crud->display_as('officeCode','Office City');
    $crud->set_subject('Employee');
    $crud->required_fields('lastName');
    $crud->set_field_upload('file_url','assets/uploads/files');
    $output = $crud->render();
    $this->_example_output($output);        
}

Contoh menggunbakan class GroceryCRUD di Controller

 public function employees_example()
    {
        $crud = new grocery_CRUD();
 
        $crud->set_table('employees');
        $output = $crud->render();
 
        $this->_example_output($output);                
    }
 
    function _example_output($output = null)
 
    {
        $this->load->view('our_template.php',$output);    
    }    
}
 
Fungsi-fungsi lain :
- $crud->set_table('your_table_name');
- $crud->set_subject('your_subject_name');   : semua kata2="record" diganti 
- $crud->columns('field_name1','field_name2','field_name3','field_name4');
  menentukan kolom2 yg ditampilkan pada grid
- $crud->fields('field_name1','field_name2','field_name3','field_name4');
  menentukan kolom2 pd table yang ditampilkan pada add/Edit screen
 
- $crud->add_fields('username','password','first_name','last_name');
  $crud->edit_fields('username','first_name','last_name'); 
  jika ingin membedakan field2 yg ingin ditampilkan pada latyar add/edit 
 
-  $crud->display_as('lastName','Last Name');
   $crud->display_as('firstName','First Name');
   $crud->display_as('jobTitle','Job Title');
   menganti display nama field pada table
 
VALIDASI FILED SAAT INPUT/EDIT 
-  $crud->required_fields('field_name_1','field_name_2','field_name_3');
- $crud->set_rules('quantityInStock','Quantity In Stock','integer');
                  (filed,label,rule)
 
  
 DISABLE FIELD DAN TOMBOL EDIT/DELETE
-$crud->unset_edit(); 
unset_add, unset_edit,unset_delete and unset_list

-$crud->unset_texteditor('field_name_1','field_name_2','field_name_3');
 menghilangkan texteditor pd field tertentu 


Install Grocery pada Codeigniter

The installation is really easy. You just copy all the files to your project and you are ready to use grocery CRUD.

- load library grocery di __construct() pd Controller:
$this->load->library('grocery_CRUD');
 
- Buat fungsi di contoller untuk menampilkan table 
 public function employees()
    {
         $crud = new grocery_CRUD();
 
    $crud->set_theme('datatables');
    $crud->set_table('employees');
    $crud->set_relation('officeCode','offices','city');
    $crud->display_as('officeCode','Office City');
    $crud->set_subject('Employee');
 
    $crud->required_fields('lastName');
     $output = $crud->render();
 
        $this->_example_output($output);        
    }
 
    function _example_output($output = null)
 
    {
        $this->load->view('our_template.php',$output);    
    } 
 
 - Tambnahkan di View :
 - diantara head tag
<?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; ?>
- diantara Body tag :
  <?php echo $output; ?>