ErrorException [错误]:在非对象上调用成员函数save()

时间:2017-10-23 12:23:28

标签: fuelphp

我一直在接受这个问题,我不知道Fuelphp所以我不确定它是如何完全运行的,但是这是我添加$program->save();

之后我的代码停止工作的地方
   $setup->network_rep_comission = Input::post('standard_comission');
             $setup->message = Input::post('message');
            $setup->updated_at = date("Y-m-d H:i:s", time());
             $program->commission_rate = Input::post('commission_rate');
            $setup->save();
            $program->save();
           Session::set_flash('success', "Settings saved successfully");

        }

       $this->template->set_global('setup', $setup);// = "Setup";

是因为我有双重保存吗?我怎样才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

首先,你的Fuel Php核心系统是否过载?如果不是,您可以使用\ Input :: post()而不是Input :: post()。

//Secondly put your datas on one array like :
//Don't forgot to put your code on a try catch too

try{
  $setup = array(
     'rep_commission' => \Input::post('network_rep_comission');
     'message'        => \Input::post('message'),
     'updated_at'     => \Input::post('updated_at')
  );
  $program = array(
     'commission_rate' => \Input::post('commission_rate'),
  );

  //Then you can convert your array with your objects properties using setters 
  //methods of your object model :

  \DB::start_transaction();

  $this->setup = new \Model_Setup();
  $this->setup->set_network_rep_comission($setup['rep_commission']);
  $this->setup->set_message($setup['message']);
  $this->setup->set_updated_at($setup['updated_at']);

  $this->setup->save();

  $this->program = new \Model_Program();
  $this->program->set_commission_rate($program['commission_rate']);

  $this->program->save();

  \DB::commit_transaction();

  \Session::set_flash('success', "Settings saved successfully");

}catch(\Exception $ex){
   \DB::rollback_transaction();

}
  $this->template->set_global(array(
     'setup' => $this->setup
  ));

我希望它可以帮助你,这是我对堆栈溢出的第一个评论^^