[英]How to call a function from model in controller with an OpenCart module?
I hope this isn't to vague, I am still a beginner to the idea of the MVC-L framework. 我希望这不是模糊的,我仍然是MVC-L框架的初学者。 I'm in the process of creating an Open-cart 1.5.1.3 module, and from what I can gather OC 1.5+ will call the install() function automatically from within you controller when you first install the a module (if you provide install() function that is).
我正在创建一个Open-cart 1.5.1.3模块,从我可以收集的内容中,OC 1.5+将在您第一次安装模块时自动从您的控制器中调用install()函数(如果您提供安装) ()函数是)。 Where I'm having trouble is with actually calling a function (which creates a new database table) which is located in the model from my controller function install().
我遇到麻烦的地方是实际调用一个函数(创建一个新的数据库表),该函数位于模型中,来自我的控制器函数install()。
Here is the code I have already: 这是我已经拥有的代码:
Controller : TrademeXml 控制器:TrademeXml
public function install() {
$this->load->model('model/TrademeXml');
// Create table to store TradeMe ID
$this->model_model_TradmeXml->createModuleTables();
}
Model : TradmeXml 型号:TradmeXml
public function createModuleTables() {
$query = $this->db->query("CREATE TABLE IF NOT EXISTS " . DB_PREFIX . "trademeID (tid INT(30), PRIMARY KEY(tid)");
}
The install function is called during the installation of the module, but I get the following error: 在安装模块期间调用install函数,但是我收到以下错误:
Fatal error: Call to a member function createModuleTables() on a non-object in D:\\xampp\\htdocs\\store\\admin\\controller\\module\\TrademeXml.php 致命错误:在D:\\ xampp \\ htdocs \\ store \\ admin \\ controller \\ module \\ TrademeXml.php中的非对象上调用成员函数createModuleTables()
$this->load->model('module/tradexml');
$this->model_module_tradexml->createModuleTables();
I was missing this... 我错过了这个......
public function index() {
$this->install();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.