0

我a,尝试对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');

难道我做错了什么?

4

3 回答 3

1

解决了伙计们。

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

有点脑残,上面的行应该是:

$childCat = $this->getChildCategory($data['school']);
于 2012-11-14T13:36:15.290 回答
0

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

于 2012-11-14T12:07:55.017 回答
0

你确定把文件放进去catalog/model/account/children.php吗?如果是这样,您是否收到任何有助于调试的错误消息?另外,当您运行代码时,您确定其中$data['children-name']包含数据吗?

于 2012-11-14T12:09:24.140 回答