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.

6
  • 1
    magento.stackexchange.com/questions/274903/… Commented May 21, 2019 at 8:58
  • Thank you for the link Commented May 24, 2019 at 5:16
  • Thanks for Help... I Need to Know the Insert and select operation (without use to model) It's Possible or Not? Commented May 24, 2019 at 5:34
  • 1
    Yes possible via sql query in that case you don't model and all just a table to perform actions on it @manoji Commented May 24, 2019 at 5:35
  • 1
    Ask a separate question may myself or someone will answer to that @manoji Commented May 24, 2019 at 5:40

1 Answer 1

2

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

answered May 21, 2019 at 9:27
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.