Guest User

Untitled

a guest
Jun 21st, 2015
242
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //helper functions
  2.     public function resetData($model,$id = null) {
  3.         if(is_null($id)){
  4.             $data = $model->getCollection()
  5.                 ->allTables()
  6.                 ->getData();
  7.         } else {
  8.             $data = $model->getCollection()
  9.                 ->allTables()
  10.                 ->addFieldToFilter('coupon_id', array('eq'=>$id))
  11.                 ->getData();
  12.         }
  13.         Mage::getSingleton('adminhtml/session')->setCsmData($data);
  14.     }
  15.  
  16.     public function prepareAcctForm($form, $model, $id = null) {
  17.         $this->resetData($model,$id);
  18.         $data = Mage::getSingleton('adminhtml/session')->getCsmData();
  19.         $data = $data[0];
  20.         $form->setDataObject($data);
  21.         return array('data' => $data,'form' => $form);
  22.     }
  23.  
  24. //Form.php
  25.         $p = Mage::helper('csm')->prepareAcctForm($form,Mage::getModel('csm/csm'),$this->getRequest()->getParam('id'));
  26.         $form = $p['form'];
  27.         $data = $p['data'];
  28.  
  29. /* insert fields */
  30.  
  31.         $this->setForm($form);
  32.     /*this used to be $form->setValues($data); and it didn't work. Changed to add and it did.
  33.         $form->addValues($data);
RAW Paste Data