Question

Am trying to perform an update and nothing seems to work. It has something to do with my callback I suppose as the update works well when the callback is disabled. This is my try block.

try{
      $updatestat=NULL;
      $updateresult=NULL;
      $id = Arr::get($_POST, 'id');

      $scode=trim(Arr::get($_POST, 'stationcode'));
      $sname=trim(Arr::get($_POST, 'stationname'));
      $dsupdate = new Model_Dstations($id);
      $dsupdate->scode = $scode;
      $dsupdate->sname = $sname;

      $validation = new Validation($_POST);          
  $validation->rule('scode', array($dsupdate, 'check_updatecheck' ), array( ':validation', ':value',':field',$id ));
      $validation->rule('sname', array($dsupdate, 'check_updatecheck' ), array( ':validation', ':value',':field',$id ));
      $result['sql']=$dsupdate->save($validation);}
Was it helpful?

Solution

Your code looks like a complete mess. Try this:

  $dsupdate = new Model_Dstations($id);

  $validation = new Validation($_POST);          
  $validation->rule('scode', array($dsupdate, 'check_updatecheck' ), array( ':validation', ':value',':field',$id ));
  $validation->rule('sname', array($dsupdate, 'check_updatecheck' ), array( ':validation', ':value',':field',$id ));

  if ($validation->check()) {
      $dsupdate->scode = $scode;
      $dsupdate->sname = $sname;
      $dsupdate->save();
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top