2

I have create a custom module and database-table using following this steps and i understand the table displaying in customer_side.

Now I Need to Know the Insert operation in customer_side please give me any example or link for insertion process custom module in magento2.

1

If you have model for your custom table then you do all these stuffs in the below way

Try this,

Di method :

Inject your model in your constructor

 protected function __construct(
 ....
 \Vendor\ModuleName\Model\ModelName $customTable,
 ....
 )
{
   ...
   $this->customTable = $customTable;
   ...
}

then on your execute function from controller

execute()
{
  // insert
  $model = $this->customTable->create();
  // update
  $model = $this->customTable->create();
  $model->load('id',$id_to_update);

  $model->setField_Name('values to be stored');
  $model->save();
}

In order to get collection

$model = $this->customTable->create()->getCollection();
foreach($model as $item){
    echo $item->getFiledName();      
}

Hope this helps.
Copied form Insert, Update values in existing custom table and Select values from that table. Magento2

  • It's code is working thanks – manoji May 24 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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