繁体   English   中英

无法将新模型添加到opencart

[英]Can't add new model to opencart

我试图在opencart中对注册过程进行修改。 我修改了视图中的表单,并将值发布到account / customer.php模型中,在其中添加了一些代码来处理新字段,如下所示:

/* add children and links to product categories */
    $this->load->model('account/children');
    //loop childrens names to use key for remaining info
    foreach($data['children-name'] as $key=>$name){
        //re-assign data and purify
        $child['name'] = mysql_real_escape_string($name);
        $child['surname'] = mysql_real_escape_string($data['children-surname'][$key]);
        $child['gender'] = mysql_real_escape_string($data['children-gender'][$key]);
        $child['dob'] = mysql_real_escape_string($data['children-dob'][$key]);
        $child['school'] = mysql_real_escape_string($data['children-school'][$key]);
        $child['unit'] = mysql_real_escape_string($data['children-unit'][$key]);
        $child['height'] = mysql_real_escape_string($data['children-height'][$key]);
        $child['chest'] = mysql_real_escape_string($data['children-chest'][$key]);
        $child['waist'] = mysql_real_escape_string($data['children-waist'][$key]);
        $child['waistToKnee'] = mysql_real_escape_string($data['children-waist-to-knee'][$key]);
        $child['insideLeg'] = mysql_real_escape_string($data['children-inside-leg'][$key]);
        $child['shoeSize'] = mysql_real_escape_string($data['children-shoe-size'][$key]);
        $child['customerId'] = $customer_id;

        //update/create child record
        $this->model_account_children->addChild($child);
    }
    /* end add children and links to product categories */

然后,我在account / children.php中创建了相对模型文件,其中包含以下代码:

class ModelAccountChildren extends Model {
    public function addChild($data) {
        //create other fields not in $data
        $lastUpdated = date('Y-m-d h:i:s');
        $childCat = getChildCategory($data['school']);
        $dob = date('Y-m-d h:i:s', $date['dob']);
        if($data['gender'] == 'm'){
            $data['gender'] = 'Male';
        }else{
            $data['gender'] = 'Female';
        }
        echo "INSERT INTO " . DB_PREFIX . "customer_children (customer_id, child_name, child_surname, child_gender, child_dob, category_id, child_school, child_unit, child_height, child_chest, child_waist, child_waist_to_knee, child_inside_leg, child_shoe_size, child_last_updated) VALUES (".$data['customerId'].", '".$data['name']."', '".$data['surname']."', '".$data['gender']."', '".$dob."', ".$childCat['category_id'].", '".$data['school']."', '".$data['unit']."', '".$data['unit']."', '".$data['height']."', '".$data['chest']."', '".$data['waist']."', '".$data['waistToKnee']."', '".$data['insideLeg']."', '".$data['shoeSize']."', '".$lastUpdated."')";
        //perform insert
        $this->db->query("INSERT INTO " . DB_PREFIX . "customer_children (customer_id, child_name, child_surname, child_gender, child_dob, category_id, child_school, child_unit, child_height, child_chest, child_waist, child_waist_to_knee, child_inside_leg, child_shoe_size, child_last_updated) VALUES (".$data['customerId'].", '".$data['name']."', '".$data['surname']."', '".$data['gender']."', '".$dob."', ".$childCat['category_id'].", '".$data['school']."', '".$data['unit']."', '".$data['unit']."', '".$data['height']."', '".$data['chest']."', '".$data['waist']."', '".$data['waistToKnee']."', '".$data['insideLeg']."', '".$data['shoeSize']."', '".$lastUpdated."')");
    }

    public function updateChild($data) {

    }

    public function getChildCategory($childSchoolStr){
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_description WHERE name LIKE '" . $childSchoolStr . "'");

        return $query->row;
    }
}

由于某种原因,脚本无法在该行的model / account / customer.php中调用该新模型:

$this->load->model('account/children');

难道我做错了什么?

解决这个问题。

$childCat = getChildCategory($data['school']);

脑流失的一点,上面的行应该是:

$childCat = $this->getChildCategory($data['school']);

对我来说似乎正确。 您可以在模型中使用它。 您使用vqmod吗? 尝试删除缓存文件。 也许在模型中添加一个测试函数,看看可以调用它了。 您得到什么错误?

您是否已将文件肯定地放在catalog/model/account/children.php 如果是这样,您是否得到任何错误消息,将有助于调试此消息? 另外,在运行代码时,是否确定$data['children-name']包含数据?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM