Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TUTORIAL CI - Grocerycrud - Contoh Foto Member
#1
berikut contoh data siswa berikut foto:

PHP Code:
<?php

    
public function index() {
        
$this->_init();
        
$this->load->library('grocery_CRUD');
        
$this->output->set_title('Pengaturan Data Siswa');
        
$crud = new grocery_CRUD();

        
$this->load->config('grocery_crud');
        
$this->config->set_item('grocery_crud_file_upload_allow_file_types''gif|jpeg|jpg|png');

         
$crud->set_subject('Data Siswa');
        
$crud->set_table('t_siswa');
        
$crud->where('aktif''1');

        
$crud->columns('file_pic','nisn''nama''gender''tanggal_lahir''username''aktif''ket');
        
$crud->fields('nisn''nama''gender''tmpt_lahir''tanggal_lahir''alamat''no_tlpn_rmh''no_tlpn_ayah''no_tlpn_ibu''nama_ayah''nama_ibu''username','pass''aktif''ket''file_pic');

        
$crud->field_type('aktif','dropdown', array('1' => 'Active''2' => 'Pending''3' => 'Alumni / Lulus''4' => 'Pindah Sekolah'));
        
        
$crud->order_by('t_siswa.aktif ASC, t_siswa.nisn, id');

        
$crud->display_as('nama','Nama Lengkap');
        
$crud->display_as('file_pic','Photo');
        
$crud->display_as('username','Username');
        
$crud->display_as('pass','Password');
        
$crud->display_as('aktif','Status');
        
$crud->display_as('ket','Keterangan');

        
$crud->set_field_upload('file_pic','assets/uploads/siswa');
        
$crud->callback_after_upload(array($this,'callback_after_upload'));

        
$crud->required_fields('nisn''aktif''username');
        
$crud->unique_fields('username''nisn');
        
$crud->set_rules('nama''Nama Lengkap','required|callback_nama_check');

        
$crud->callback_edit_field('pass',array($this,'_set_password_input_to_empty'));
        
$crud->callback_add_field('pass',array($this,'_set_password_input_to_empty'));

        
$crud->callback_before_insert(array($this,'encrypt_password_callback'));
        
$crud->callback_before_update(array($this,'encrypt_password_callback'));

        
$crud->callback_before_delete(array($this,'cek_before_delete'));
        
$crud->set_lang_string('delete_error_message''Data tidak dapat dihapus, karena masih ada data lain yang terkait dengan data ini.');

        
$crud->callback_column('file_pic',array($this,'callback_column_pic'));

        
$crud->unset_read();
        
        
$output $crud->render();

        }

         
$this->load->view('admin/jin_crud_view',$output);
         

    }

    function 
callback_column_pic($value$row) {
        if(
$value) {
            return 
'<a class="image-thumbnail" href="'.base_url().'assets/uploads/siswa/' $value .'"><img src="'.base_url().'assets/uploads/siswa/' $value '" alt="' $value '" width="32" height="32" /></a>';
        } else {
            return 
'<img src="'.base_url().'assets/themes/jin_admin/assets/img/avatar1.png" alt="default" width="32" height="32" />';
        }
    }

    function 
callback_after_upload($uploader_response,$field_info$files_to_upload) {
        
$this->load->library('image_moo');
        
//Is only one file uploaded so it ok to use it with $uploader_response[0].
        
$file_uploaded $field_info->upload_path.'/'.$uploader_response[0]->name;
        
$this->image_moo->load($file_uploaded)->resize(250,250)->save($file_uploaded,true);
        return 
true;
    }

    function 
nama_check($str) {
        if(
preg_match('/^[0-9a-z \.\']+$/i'$str)) {
            return 
TRUE;
        } else {
            
$this->form_validation->set_message('nama_check''Kolom <strong>Nama Lengkap</strong> tidak boleh menggunakan character aneh. Silahkan gunakan: A-Z a-z 0-9 . (titik) dan \' (koma atas)');
            return 
FALSE;
        }
    }

    function 
_set_password_input_to_empty() {
        return 
"<input type='password' name='pass' value='' /><br />Kosongkan password jika tidak ingin ubah/isi.";
    }

    function 
encrypt_password_callback($post_array) {
        if(!empty(
$post_array['pass'])) {
            
$post_array['pass'] = md5($post_array['pass']);
        } else {
            unset(
$post_array['pass']);
        }
        return 
$post_array;
    }

    function 
cek_before_delete($primary_key) {
        
$this->db->db_debug false;
        
$this->db->trans_begin();
        
$this->db->where('id'$primary_key);
        
$this->db->delete('t_siswa');
        
$num_rows $this->db->affected_rows();
        
$this->db->trans_rollback();
        if (
$num_rows 0) {
            return 
TRUE;
        } else {
            return 
FALSE;
        }
    } 
Reply
#2
ijin copas ya om, dari kemaren bikin script sendiri seperti ini gak bisa bagus hasilnya
Reply
#3
Makasih banyak atas informasinya ya master
Reply
#4
Hasilnya lebih keren dari code script yang aku punya. Ijin copas ya mastah
Reply
#5
sangat simpel sekali jadi lebih mudah
Reply
#6
apakah anak akutansi yang bisa buat laporan seperti ini
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)