Error Number: 1096 Error Number: 1096 No tables - codeigniter

class model_trans_gc extends CI_Model{
function trans_gc_add()
{
$add=array(
'trans_gc_date' => $this->input->post('trans_gc_date'),
'trans_gc_no' => $this->input->post('trans_gc_no'),
'trans_gc_consname' => $this->input->post('trans_gc_consname'),
'trans_gc_consbank' => $this->input->post('trans_gc_consbank'),
'trans_gc_consname_add' => $this->input->post('trans_gc_consname_add'),
'trans_gc_consbank_add' => $this->input->post('trans_gc_consbank_add'),
'trans_gc_comp' => $this->input->post('trans_gc_comp'),
'trans_gc_pol' => $this->input->post('trans_gc_pol'),
'trans_gc_amt' => $this->input->post('trans_gc_amt'),
'trans_gc_insdate' => $this->input->post('trans_gc_insdate'),
'trans_gc_risk' => $this->input->post('trans_gc_risk'),
'trans_gc_from' => $this->input->post('trans_gc_from'),
'trans_gc_to' => $this->input->post('trans_gc_to'),
'trans_gc_packno' => $this->input->post('trans_gc_packno'),
'trans_gc_packdesc' => $this->input->post('trans_gc_packdesc'),
'trans_gc_actweight' => $this->input->post('trans_gc_actweight'),
'trans_gc_charweight' => $this->input->post('trans_gc_charweight'),
'trans_gc_method_pack' => $this->input->post('trans_gc_method_pack'),
'trans_gc_frt' => $this->input->post('trans_gc_frt'),
'trans_gc_hamali' => $this->input->post('trans_gc_hamali'),
'trans_gc_sr' => $this->input->post('trans_gc_sr'),
'trans_gc_aoc' => $this->input->post('trans_gc_aoc'),
'trans_gc_doorcln' => $this->input->post('trans_gc_doorcln'),
'trans_gc_doordel' => $this->input->post('trans_gc_doordel'),
'trans_gc_riskch' => $this->input->post('trans_gc_riskch'),
'trans_gc_dem' => $this->input->post('trans_gc_dem'),
'trans_gc_gc' => $this->input->post('trans_gc_gc'),
'trans_gc_total' => $this->input->post('trans_gc_total'),
'trans_gc_paymode' => $this->input->post('trans_gc_paymode'),
'trans_gc_crno' => $this->input->post('trans_gc_crno'),
'status' => '1'
);
$this->db->insert('trans_gc_add',$add);
$query=$this->db->get();
return $query->result();
}
}
Database Error Occurred
Error Number: 1096
No tables used
SELECT *
Filename: C:\xampp\htdocs\speed\system\database\DB_driver.php
Line Number: 330
please help me to resolve this problem

Remove those lines:
$query=$this->db->get();
return $query->result();
You are inserting into the db, then you are running empty query with get()
If you want to return if the data was successfully inserted or not, then do this:
return $this->db->insert('trans_gc_add',$add);
If you want to return the inserted data:
return $add;
http://ellislab.com/codeigniter/user-guide/database/active_record.html#insert

Related

fail to update data into database

Controller
function edit($RegNo){
$data['row'] = $this->ManageTrenter code hereansfers->GetById($RegNo);
$this->load->view('admin/transferupdate', $data);
}
enter code here
public function update($RegNo){
$this->ManageT`enter code here`ransfers->update($RegNo);
redirect('admin/ManageTransfer/transfer');
}
Model
function GetById($RegNo){
return $this->db->get_where('user_transfer', array('RegNo' => $RegNo ))->row();
}
function update($RegNo){
$arr['School'] = $this->input->post('School');
$arr['Date'] = $this->input->post('Date');
$arr['RegNo'] = $this->input->post('RegNo');
$arr['Class'] = $this->input->post('Class');
$arr['New'] = $this->input->post('New');
$arr['Reason'] = $this->input->post('Reason');
$arr['UserId'] = $this->input->post('UserId');
$arr['Status'] = $this->input->post('Status');
$this->db->where(array('RegNo' => $RegNo));
$this->db->update('user_transfer', $arr);
}
View
RegNo);?>">
error occur
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: admin/transferupdate.php
Line Number: 12
replace
$this->db->where(array('RegNo' => $RegNo));
like this
$this->db->where('RegNo', $RegNo);
function update($RegNo){
$arr= array();
$post_data=$this->input->post();
$arr=(
'School' => $post_data['School'],
'Date' => $post_data['Date'],
'RegNo' => $post_data['RegNo'],
'Class' => $post_data['Class'],
'New' => $post_data['New'],
'Reason' => $post_data['Reason'],
'UserId' => $post_data['UserId'],
'Status' => $post_data['Status']
);
$this->db->where('RegNo', $RegNo);
$this->db->update('user_transfer', $arr);
}

Laravel Error Update with foreach : syntax error, unexpected ' ' (T_STRING), expecting ']'

I have DB in SQL Server and I execute it with Laravel. However, I get the following error.
ParseError syntax error, unexpected ' ' (T_STRING), expecting ']'
I am trying to figure out why this is happening. It shows this syntax error, but I don't understand it. I can't find a typo. I read and update SQL Server database. Is there a bug or something?
$siswa_regNo = DB::table('upload_tbpendaftaran$')
->select('Reg_No', 'F_Name',
'N_Name',
'Place',
'Birthday',
'BirthID',
'Gender',
'Bloods',
'Glass',
'Height',
'Weight',
'Child_No',
'Child_Qty',
'School_Code',
'School_Name',
'School_Address',
'School_Distric',
'School_Distric_Desc',
'School_City',
'School_City_Desc',
'School_Province',
'School_Province_Desc',
'School_NEM_Avg',
'School_STTB',
'Certificate_ID',
'Stay',
'Stay_Address',
'Stay_RT',
'Stay_RW',
'Stay_Village',
'Stay_Distric',
'Stay_Distric_Desc',
'Stay_City',
'Stay_City_Desc',
'Stay_Province',
'Stay_Province_Desc',
'Stay_Phone',
'Stay_HP',
'Stay_Postal',
'Stay_Longitude',
'Stay_Latitude',
'Home_Address',
'Home_RT',
'Home_RW',
'Home_Village',
'Home_Distric',
'Home_Distric_Desc',
'Home_City',
'Home_City_Desc',
'Home_Province',
'Home_Province_Desc',
'Home_Postal',
'Home_Phone',
'Home_HP',
'Home_HP2',
'Home_Longitude',
'Home_Latitude',
'EMail',
'Email_Parent',
'Email_Parent2',
'ID_Cards',
'Distance',
'Time_HH',
'Time_MM',
'TransportID',
'TransportDesc',
'Remarks',
'NISN',
'ExamUNNo')
->orderBy('Reg_No')
->get();
foreach ($siswa_regNo as $s) {
DB::table('Registration')
->where('Reg_No', $s->Reg_No)
->update([
'F_Name' => $s->F_Name,
'N_Name' => $s->N_Name,
'Place' => $s->Place,
'Birthday' => $s->Birthday,
'BirthID' => $s->BirthID,
'Gender' => $s->Gender,
'Religion' => $s->Religion,
'Citizen' => $s->Citizen,
'FamilyID' => $s->FamilyID,
'Bloods' => $s->Bloods,
'Glass' => $s->Glass,
'Height' => $s->Height,
'Weight' => $s->Weight,
'Child_No' => $s->Child_No,
'Child_Qty' => $s->Child_Qty,
'School_Code' => $s->School_Code,
'School_Name' => $s->School_Name,
'School_Address' => $s->School_Address,
'School_Distric' => $s->School_Distric,
'School_Distric_Desc' => $s->School_Distric_Desc,
'School_City' => $s->School_City,
'School_City_Desc' => $s->School_City_Desc,
'School_Province' => $s->School_Province,
'School_Province_Desc' => $s->School_Province_Desc,
'School_NEM_Avg' => $s->School_NEM_Avg,
'School_STTB' => $s->School_STTB,
'Certificate_ID' => $s->Certificate_ID,
'Stay' => $s->Stay,
'Stay_Address' => $s->Stay_Address,
'Stay_RT' => $s->Stay_RT,
'Stay_RW' => $s->Stay_RW,
'Stay_Village' => $s->Stay_Village,
'Stay_Distric' => $s->Stay_Distric,
'Stay_Distric_Desc' => $s->Stay_Distric_Desc,
'Stay_City' => $s->Stay_City,
'Stay_City_Desc' => $s->Stay_City_Desc,
'Stay_Province' => $s->Stay_Province,
'Stay_Province_Desc' => $s->Stay_Province_Desc,
'Stay_Phone' => $s->Stay_Phone,
'Stay_HP' => $s->Stay_HP,
'Stay_Postal' => $s->Stay_Postal,
'Stay_Longitude' => $s->Stay_Longitude,
'Stay_Latitude' => $s->Stay_Latitude,
'Home_Address' => $s->Home_Address,
'Home_RT' => $s->Home_RT,
'Home_RW' => $s->Home_RW,
'Home_Village' => $s->Home_Village,
'Home_Distric' => $s->Home_Distric,
'Home_Distric_Desc' => $s->Home_Distric_Desc,
'Home_City' => $s->Home_City,
'Home_City_Desc' => $s->Home_City_Desc,
'Home_Province' => $s->Home_Province,
'Home_Province_Desc' => $s->Home_Province_Desc,
'Home_Postal' => $s->Home_Postal,
'Home_Phone' => $s->Home_Phone,
'Home_HP' => $s->Home_HP,
'Home_HP2' => $s->Home_HP2,
'Home_Longitude' => $s->Home_Longitude,
'Home_Latitude' => $s->Home_Latitude,
'EMail' => $s->EMail,
'Email_Parent' => $s->Email_Parent,
'Email_Parent2' => $s->Email_Parent2,
'ID_Cards' => $s->ID_Cards,
'Distance' => $s->Distance,
'Time_HH' => $s->Time_HH,
'Time_MM' => $s->Time_MM,
'TransportID' => $s->TransportID,
'TransportDesc' => $s->TransportDesc,
'Remarks' => $s->Remarks,
'NISN' => $s->NISN,
'ExamUNNo' => $s->ExamUNNo
]);
}
I am very confused, please help.
in second FOREACH, when you are getting data from DB you should add ->first() or ->get() in the last.
foreach ($siswa_regNo as $s) {
DB::table('Registration')
->where('Reg_No', $s->Reg_No)
->first() // this line added
->update([
'F_Name' => $s->F_Name,
'N_Name' => $s->N_Name,
'Place' => $s->Place,
.
.
.
]);
}
or if you want to use ->get() you should foreach to this also...

Edit Form in Laravel: Creates New Entry instead of Updating Old Data

I tried to create edit method on form data submission, but instead of updating the old entry, it creates a new entry in the database.
My source files are:
web.php
Route::get('/input_gedung_bangunan/{id_bangunan}', 'input_gedung_bangunan#tampiledit');
Route::post('/data_gedung_bangunan/hitung_data', 'input_gedung_bangunan#store');
Controller:
public function store(Request $request){
//DB::enableQueryLog();
//$id_bangunan = $id;
$validation = \App\Tbl_uraian_datas::where('id_bangunan', '=', $request->get('id_bangunan'))->first();
if(is_null($validation)){
$tbl_uraian_datas = new \App\Tbl_uraian_datas;
$tbl_uraian_datas->id_bangunan = $request->get('id_bangunan');
$tbl_uraian_datas->id_kanwil = Input::get('IDKanwil');
$tbl_uraian_datas->id_kota_kab = Input::get('IDKotaKab');
$tbl_uraian_datas->nomor_baris = Input::get('NomorBaris');
$tbl_uraian_datas->nama_bangunan = Input::get('NamaBangunan');
$tbl_uraian_datas->alamat_bangunan = Input::get('AlamatBangunan');
$tbl_uraian_datas->nama_kota_kab = Input::get('Kota/Kabupaten');
$tbl_uraian_datas->kode_barang = Input::get('KodeBarang');
$tbl_uraian_datas->nup_barang = Input::get('NUPBarang');
$tbl_uraian_datas->luas_lantai = Input::get('LuasLantai');
$tbl_uraian_datas->jumlah_lantai = Input::get('JumlahLantai');
$tbl_uraian_datas->tahun_penilaian = Input::get('TahunPenilaian');
$tbl_uraian_datas->tahun_dibangun = Input::get('TahunDibangun');
$tbl_uraian_datas->tahun_direnovasi = Input::get('TahunDirenovasi');
$tbl_uraian_datas->id_jenis_bangunan = Input::get('IDJenisBangunan');
$tbl_uraian_datas->jenis_bangunan = Input::get('JenisBangunan');
$tbl_uraian_datas->id_kategori = Input::get('IDKategoriBangunan');
$tbl_uraian_datas->kategori_bangunan = Input::get('KategoriBangunan');
$tbl_uraian_datas->id_kondisi = Input::get('IDKondisiBangunan');
$tbl_uraian_datas->kondisi_bangunan = Input::get('KondisiBangunan');
$tbl_uraian_datas->luas_carport = Input::get('LuasCarport');
$tbl_uraian_datas->panjang_pagar_material1 = Input::get('PanjangPagar1');
$tbl_uraian_datas->panjang_pagar_material2 = Input::get('PanjangPagar2');
$tbl_uraian_datas->panjang_pagar_material3 = Input::get('PanjangPagar3');
$tbl_uraian_datas->harga_per_m2 = Input::get('Hargaperm2');
$tbl_uraian_datas->alasan_fisik = Input::get('Alasan1');
$tbl_uraian_datas->penyusutan = Input::get('Penyusutan');
$tbl_uraian_datas->alasan_penyusutan = Input::get('Alasan2');
$tbl_uraian_datas->save();
}else{
//Edit Data Gedung/Bangunan
$tbl_uraian_datas = \App\Tbl_uraian_datas::update(['id_kanwil' => Input::get('IDKanwil'), 'id_kota_kab' => Input::get('IDKotaKab'), 'nomor_baris' => Input::get('NomorBaris'),'nama_bangunan' => Input::get('nama_bangunan'),'alamat_bangunan' => Input::get('AlamatBangunan'),'nama_kota_kab' => Input::get('Kota/Kabupaten'),'kode_barang' => Input::get('KodeBarang'),'nup_barang' => Input::get('NUPBarang'),'luas_lantai' => Input::get('LuasLantai'),'jumlah_lantai' => Input::get('JumlahLantai'),'tahun_penilaian' => Input::get('TahunPenilaian'),'tahun_dibangun' => Input::get('TahunDibangun'),'tahun_direnovasi' => Input::get('TahunDirenovasi'),'id_jenis_bangunan' => Input::get('IDJenisBangunan'),'jenis_bangunan' => Input::get('JenisBangunan'),'id_kategori' => Input::get('IDKategoriBangunan'),'kategori_bangunan' => Input::get('KategoriBangunan'),'id_kondisi' => Input::get('IDKondisiBangunan'),'kondisi_bangunan' => Input::get('KondisiBangunan'),'luas_carport' => Input::get('LuasCarport'),'panjang_pagar_material1' => Input::get('PanjangPagar1'),'panjang_pagar_material2' => Input::get('PanjangPagar2'),'panjang_pagar_material3' => Input::get('PanjangPagar3'),'harga_per_m2' => Input::get('Hargaperm2'),'alasan_fisik' => Input::get('Alasan1'),'penyusutan' => Input::get('Penyusutan'),'alasan_penyusutan' => Input::get('Alasan2')]);
//$tbl_hasil_perhitungans = \App\Tbl_hasil_perhitungans::where('id_bangunan', '=',$request->get('id_bangunan'))->update(['umur_efektif_bangunan' => Input::get('nUmurEfektifBangunan'), 'pembulatan' => Input::get('nPembulatan')]);
$request->session()->flash('alert-success', 'Data Gedung Bangunan was successfully added!');
return back();
}
}
It looks like the controller keeps making the new id for the editted data and I don't know what I did wrong in my controller.
Instead of the following lines in your code:
$validation = \App\Tbl_uraian_datas::where('id_bangunan', '=', $request->get('id_bangunan'))->first();
if(is_null($validation)){
Try this:
$validation = \App\Tbl_uraian_datas::where('id_bangunan', $request->input('id_bangunan'))->first();
if(empty($validation)){
AND
instead of
$tbl_uraian_datas = \App\Tbl_uraian_datas::update(['id_kanwil' => Input::get('IDKanwil'), 'id_kota_kab' => Input::get('IDKotaKab'), 'nomor_baris' => Input::get('NomorBaris'),'nama_bangunan' => Input::get('nama_bangunan'),'alamat_bangunan' => Input::get('AlamatBangunan'),'nama_kota_kab' => Input::get('Kota/Kabupaten'),'kode_barang' => Input::get('KodeBarang'),'nup_barang' => Input::get('NUPBarang'),'luas_lantai' => Input::get('LuasLantai'),'jumlah_lantai' => Input::get('JumlahLantai'),'tahun_penilaian' => Input::get('TahunPenilaian'),'tahun_dibangun' => Input::get('TahunDibangun'),'tahun_direnovasi' => Input::get('TahunDirenovasi'),'id_jenis_bangunan' => Input::get('IDJenisBangunan'),'jenis_bangunan' => Input::get('JenisBangunan'),'id_kategori' => Input::get('IDKategoriBangunan'),'kategori_bangunan' => Input::get('KategoriBangunan'),'id_kondisi' => Input::get('IDKondisiBangunan'),'kondisi_bangunan' => Input::get('KondisiBangunan'),'luas_carport' => Input::get('LuasCarport'),'panjang_pagar_material1' => Input::get('PanjangPagar1'),'panjang_pagar_material2' => Input::get('PanjangPagar2'),'panjang_pagar_material3' => Input::get('PanjangPagar3'),'harga_per_m2' => Input::get('Hargaperm2'),'alasan_fisik' => Input::get('Alasan1'),'penyusutan' => Input::get('Penyusutan'),'alasan_penyusutan' => Input::get('Alasan2')]);
Try:
$tbl_uraian_datas = \App\Tbl_uraian_datas::where('id_bangunan',$request->input('id_bangunan'))->update(['id_kanwil' => Input::get('IDKanwil'), 'id_kota_kab' => Input::get('IDKotaKab'), 'nomor_baris' => Input::get('NomorBaris'),'nama_bangunan' => Input::get('nama_bangunan'),'alamat_bangunan' => Input::get('AlamatBangunan'),'nama_kota_kab' => Input::get('Kota/Kabupaten'),'kode_barang' => Input::get('KodeBarang'),'nup_barang' => Input::get('NUPBarang'),'luas_lantai' => Input::get('LuasLantai'),'jumlah_lantai' => Input::get('JumlahLantai'),'tahun_penilaian' => Input::get('TahunPenilaian'),'tahun_dibangun' => Input::get('TahunDibangun'),'tahun_direnovasi' => Input::get('TahunDirenovasi'),'id_jenis_bangunan' => Input::get('IDJenisBangunan'),'jenis_bangunan' => Input::get('JenisBangunan'),'id_kategori' => Input::get('IDKategoriBangunan'),'kategori_bangunan' => Input::get('KategoriBangunan'),'id_kondisi' => Input::get('IDKondisiBangunan'),'kondisi_bangunan' => Input::get('KondisiBangunan'),'luas_carport' => Input::get('LuasCarport'),'panjang_pagar_material1' => Input::get('PanjangPagar1'),'panjang_pagar_material2' => Input::get('PanjangPagar2'),'panjang_pagar_material3' => Input::get('PanjangPagar3'),'harga_per_m2' => Input::get('Hargaperm2'),'alasan_fisik' => Input::get('Alasan1'),'penyusutan' => Input::get('Penyusutan'),'alasan_penyusutan' => Input::get('Alasan2')]);
You need to tell which row to actually update by giving a where clause

Insert multiple data from other table in codeigniter

I want to save the data where id_perencanaan is selected. I've tried a lot of ways, but have not found the answer.
Controller:
public function salin_barang_perencanaan($id_perencanaan) {
$barang_perencanaan = $this->perencanaan_barang_model->barang_perencanaan($id_perencanaan);
// echo "<pre>";
// print_r($barang_perencanaan);
if($barang_perencanaan->id_perencanaan == 0) {
$data = array(
'id_perencanaan_barang' => $barang_perencanaan->id_perencanaan_barang,
'id_golongan_barang' => $barang_perencanaan->id_golongan_barang,
'id_bidang_barang' => $barang_perencanaan->id_bidang_barang,
'id_kelompok_barang' => $barang_perencanaan->id_kelompok_barang,
'id_sub_kelompok_barang' => $barang_perencanaan->id_sub_kelompok_barang,
'id_jenis_barang' => $barang_perencanaan->id_jenis_barang,
'id_perencanaan' => $barang_perencanaan->id_perencanaan,
'nomor_barang' => $barang_perencanaan->nomor_barang,
'nama_barang' => $barang_perencanaan->nama_barang,
'harga_satuan' => $barang_perencanaan->harga_satuan,
'jumlah_barang' => $barang_perencanaan->jumlah_barang,
'total_harga' => $barang_perencanaan->total_harga,
'penggunaan_barang' => $barang_perencanaan->penggunaan_barang,
'keterangan' => $barang_perencanaan->keterangan,
'tanggal_post' => date('Y-m-d H:i:s'),
'id_user' => $this->session->userdata('id')
);
$this->perencanaan_model->salin_barang_perencanaan($data);
$this->session->set_flashdata('sukses', 'Perencanaan dalam tahap pengadaan');
redirect(base_url('pengadaan'));
}
$this->session->set_flashdata('sukses', 'Proses perencanaan telah dibatalkan');
redirect(base_url('perencanaan'));
}
And my model :
public function salin_barang_perencanaan($data) {
// $this->db->trans_start();
$this->db->where('id_perencanaan',$data['id_perencanaan']);
$this->db->insert_batch('pengadaan_barang',$data);
// $this->db->trans_complete();
}
I am very grateful for your help...
The problem has been resolved, the following is the code I used:
Controller :
public function salin_barang_perencanaan($id_perencanaan) {
$barang_perencanaan = $this->perencanaan_barang_model->barang_perencanaan($id_perencanaan);
// echo "<pre>";
// print_r($barang_perencanaan);
// if($barang_perencanaan->id_perencanaan == 0) {
foreach($barang_perencanaan as $barang_perencanaan){
$data = array(
'id_perencanaan_barang' => $barang_perencanaan['id_perencanaan_barang'],
'id_golongan_barang' => $barang_perencanaan['id_golongan_barang'],
'id_bidang_barang' => $barang_perencanaan['id_bidang_barang'],
'id_kelompok_barang' => $barang_perencanaan['id_kelompok_barang'],
'id_sub_kelompok_barang' => $barang_perencanaan['id_sub_kelompok_barang'],
'id_jenis_barang' => $barang_perencanaan['id_jenis_barang'],
'id_perencanaan' => $barang_perencanaan['id_perencanaan'],
// 'id_pengadaan' => $last_id,
'nomor_barang' => $barang_perencanaan['nomor_barang'],
'nama_barang' => $barang_perencanaan['nama_barang'],
'harga_satuan' => $barang_perencanaan['harga_satuan'],
'jumlah_barang' => $barang_perencanaan['jumlah_barang'],
'total_harga' => $barang_perencanaan['total_harga'],
'penggunaan_barang' => $barang_perencanaan['penggunaan_barang'],
'keterangan' => $barang_perencanaan['keterangan'],
'tanggal_post' => date('Y-m-d H:i:s'),
'id_user' => $barang_perencanaan['id_user']
);
$this->perencanaan_model->salin_barang_perencanaan($data);
}
$this->session->set_flashdata('sukses', 'Perencanaan dalam tahap pengadaan');
redirect(base_url('pengadaan'));
// }
// $this->session->set_flashdata('sukses', 'Proses perencanaan telah dibatalkan');
// redirect(base_url('perencanaan'));
}
And my model :
public function salin_barang_perencanaan($data) {
$this->db->trans_start();
$this->db->insert('pengadaan_barang' ,$data ,array('id_perencanaan' => $data['id_perencanaan']));
$this->db->trans_complete();
}

sorting and filtering not working in custom admin module

I am trying to implement an admin module in magento which has a grid in the first page and grids in the tabs while editing the grid entities.
The main grid works fine, but the grids in the tabs are not working fine.
The problem I found while I debugged the code is that, I am loading the collection in the grid with field filtering, ie I am filtering the collection with filter that is the user id. I did this because I need only data of a single user from the table. This made the entire problem, the data in the grid is coming correctly, but the filtering,sorting and searching feature inside grid is not working and returning a 404 not found error page. I tried removing the field filter I added while getting the collection, then it works fine but all the data in the table is coming which is the opposite to my requirement.
Is there any possible solution to this. Here is the way I am trying to do:
protected function _prepareCollection() {
$collection = Mage::getModel('merchant/subscriptions')->getCollection()->addFieldToFilter('user_id', Mage::registry('merchant_data')->getId());
$this->setCollection($collection); //Set the collection
return parent::_prepareCollection();
}
Thanks in advance.
ok My problem is solved there is a mistake in my code. In the grid file the function below was wrong.
public function getGridUrl() {
return $this->getUrl('*/*/transactiongrid', array('user_id',Mage::registry('merchant_data')->getId(), '_current' => true));
}
The correct method was
public function getGridUrl() {
return $this->getUrl('*/*/transactiongrid', array('user_id'=> Mage::registry('merchant_data')->getId(), '_current' => true));
}
Filter action is dependent on your below method:
public function getGridUrl() {
return $this->getUrl('*/*/grid', array('user_id' => Mage::registry('merchant_data')->getId(),'_current'=>true));
}
now this is how you will prepare collection:
protected function _prepareCollection()
{
$regData = Mage::registry('merchant_data');
if(isset($regData))
$regData = $regData->getId();
else
$regData = $this->getRequest()->getParam('user_id');
$collection = Mage::getModel('merchant/subscriptions')->getCollection()->addFieldToFilter('user_id',$regData);
...
When I dumped $regData I got this:
Cubet_Merchant_Model_Merchant Object
(
[_eventPrefix:protected] => core_abstract
[_eventObject:protected] => object
[_resourceName:protected] => merchant/merchant
[_resource:protected] =>
[_resourceCollectionName:protected] => merchant/merchant_collection
[_cacheTag:protected] =>
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
[_data:protected] => Array
(
[user_id] => 3
[firstname] => Robin
[lastname] => Cubet
[email] => robin#cubettech.com
[username] => robincubet
[password] => 51a7f45eb11fc49b5967a0039193c3ad:HSX8JkSO5lr3uaRHrzd86i7gb0RATeDb
[created] => 2013-12-12 08:34:28
[modified] => 2013-12-16 09:03:56
[logdate] =>
[lognum] => 0
[reload_acl_flag] => 1
[is_active] => 1
[extra] => N;
[rp_token] =>
[rp_token_created_at] =>
)
[_hasDataChanges:protected] =>
[_origData:protected] => Array
(
[user_id] => 3
[firstname] => Robin
[lastname] => Cubet
[email] => robin#cubettech.com
[username] => robincubet
[password] => 51a7f45eb11fc49b5967a0039193c3ad:HSX8JkSO5lr3uaRHrzd86i7gb0RATeDb
[created] => 2013-12-12 08:34:28
[modified] => 2013-12-16 09:03:56
[logdate] =>
[lognum] => 0
[reload_acl_flag] => 1
[is_active] => 1
[extra] => N;
[rp_token] =>
[rp_token_created_at] =>
)
[_idFieldName:protected] => user_id
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)

Resources