I want to save some data in to custom table.When I use static value to save data then it is going good but If I try to use dynamic data or used any calculation in between then It is going in infinite loop.

Please have look :

namespace Namespace\Module\Model;
use Magento\Framework\Model\AbstractModel;
class Test extends AbstractModel
    protected function _construct()
    public function aftersave()
        $data = $this->_objectManager->get('Namespace\Module\Model\Test')->load(10);     
       /* I also try
       $data = $this->_objectManager->create('Namespace\Module\Model\Test')->load(10);  */
    public function customValues($data)
         $date = new \Zend_Date('2016-09-12', self::DB_DATE_FORMAT);
  • you are calling same save function in after save which goes infinite May 13, 2016 at 12:43
  • first it save it call after save and in after save you are calling save function again May 13, 2016 at 12:44
  • @MineshPatel Yes but as I said if I use fixed value then issue is not generating.
    – Krupali
    May 13, 2016 at 12:58
  • seems impossible May 13, 2016 at 12:59
  • if you are saving data using model it should go in infinite for every data May 13, 2016 at 13:00

1 Answer 1


you are going into an infinite loop because the method aftersave is a callback for the save method and it is executed (as the name says) after the save is done.
So you are doing this:

save -> aftersave -> customValues-> save -> aftersave ,.... and so on.

You should never call save in a save callback.

  • @maris If I set predefine value like : $data->setDate('2016-05-17'); $data->save(); Then it is working fine. :(
    – Krupali
    May 13, 2016 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.