Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php OpenCart中的致命错误:调用未定义函数错误_Php_Mysql_Opencart - Fatal编程技术网

Php OpenCart中的致命错误:调用未定义函数错误

Php OpenCart中的致命错误:调用未定义函数错误,php,mysql,opencart,Php,Mysql,Opencart,我不想问一个已经得到回答的问题,但是我已经做了大量的研究,我被卡住了。任何帮助都将不胜感激 我正在尝试查询并将数据库结果添加到OpenCart的addproduct.tpl 在模型文件中,我有: public function units() { //function that gets database info and returns it $unit_variables = $this->db->query("SELECT unit FROM ". DB_PREFIX ."

我不想问一个已经得到回答的问题,但是我已经做了大量的研究,我被卡住了。任何帮助都将不胜感激

我正在尝试查询并将数据库结果添加到OpenCart的addproduct.tpl

在模型文件中,我有:

public function units() { //function that gets database info and returns it

$unit_variables = $this->db->query("SELECT unit FROM  ". DB_PREFIX ."
weight_class_description");

if (!$unit_variables) {

die(mysql_error());

}

else {

foreach ($unit_variables->rows as $temp_var) {

print_r($temp_var['unit'], true);

}   
}   
}
$this->load->model('catalog/product'); //where my function is located
$this->model_catalog_product->units();
$weight_variables = units(); 

if (isset($this->request->post['weight_variables'])){

$this->data['weight_variables'] = $this->request->post['weight_variables'];

}
在控制器文件中,我有:

public function units() { //function that gets database info and returns it

$unit_variables = $this->db->query("SELECT unit FROM  ". DB_PREFIX ."
weight_class_description");

if (!$unit_variables) {

die(mysql_error());

}

else {

foreach ($unit_variables->rows as $temp_var) {

print_r($temp_var['unit'], true);

}   
}   
}
$this->load->model('catalog/product'); //where my function is located
$this->model_catalog_product->units();
$weight_variables = units(); 

if (isset($this->request->post['weight_variables'])){

$this->data['weight_variables'] = $this->request->post['weight_variables'];

}
我认为:

注意:当我打印\u r$temp\u var时;不是返回print_R$temp_var,而是true并删除这些代码行$weight_variables=units;如果在控制器文件中设置$this->request->post['weight\u variables']{$this->data['weight\u variables']=$this->request->post['weight\u variables']},我的模型文件将在addproduct上显示查询结果。tpl

units是对象的一种方法,但您将其作为一个独立的常规函数调用:

$weight_variables = units();
                    ^^^^^^^
难道不是:

$weight_variables = $this->model_catalog_product->units();

相反?请注意,如前所述,您的方法实际上没有返回任何内容,因此$weight_变量将被分配为null。

您的类叫什么?class ModelCatalogProduct Extended Model您的更正修复了我对未定义函数错误的错误调用,并且您正确的$weight_变量被分配为null。如注意所示:未定义变量,但为什么函数不返回某些内容,此行不应该返回我的数据库查询print_r$temp_var['unit'],true;?