So i want to save slider_id and banner_id on muffin_bannerslider table with the purpose of tracking which slider belong to which banner and the position of the banner in a particular slider. But that table doesn't belong to any model then how should i do it . Also sorry if this topic already answered but Eng isn't my first language so to type the problem correctly to find the answer can be a challenge sometimes.
1 Answer
Can use Magento\Framework\App\ResourceConnection
Example:
use Magento\Framework\App\ResourceConnection;
class Test
{
private $resource;
public function __construct(
ResourceConnection $resource
) {
$this->resource = $resource;
}
public function save()
{
$dataset = [
'slider_id' => 1,
'banner_id' => 2,
];
$connection = $this->resource->getConnection();
$tableName = $connection->getTableName('muffin_bannerslider');
try {
$connection->insert($tableName, $dataset);
} catch (\Exception $e) {
$this->logger->critical($e->getMessage());
}
}
}