I can't find any opencart documentation and I m trying blind to create a module with connection to DB.
On admin side, i ve created an ajax button which i want call a function from model file which created the DB table, but can't figure out how to do it
Tried:
Code: Select all
<button onclick="install()">Create tables in DB</button>
...
<script type = "text/javascript">
function install() {
$.ajax( { type : 'POST',
data : { },
url : 'index.php?route=mymodule/form/install&user_token={{ user_token }}',
success: function() {
},
error: function() {
}
});
}
</script>
Code: Select all
public function install() {
$this->db->query("CREATE TABLE `" . DB_PREFIX . "_mymoduleitems` (
`req_id` int(11) NOT NULL AUTO_INCREMENT,
`status` tinyint(1) NOT NULL,
`name` varchar(64) NOT NULL,
`item0` varchar(32) NOT NULL,
`item1` text,
`date_added` datetime NOT NULL,
PRIMARY KEY (`req_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
}