0

How can i Insert, Update values in existing custom table and Select values with Magento methods not sql requests ?

asked May 16, 2019 at 12:45

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(); 
}

For more information Get custom table information

Save values into custom table

Hope this helps.

answered May 16, 2019 at 13:30
1
  • 1
    Yes! Prathap Gunasekaran thank you for good information! Commented May 16, 2019 at 14:35

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.