我是,尝试在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;
}
}
出于某种原因,脚本无法访问我在模型/ account / customer.php中调用它的新模型:
$this->load->model('account/children');
我做错了吗?
答案 0 :(得分:1)
解决了问题。
$childCat = getChildCategory($data['school']);
大脑失误,上面一行应该是:
$childCat = $this->getChildCategory($data['school']);
答案 1 :(得分:0)
对我来说似乎是对的。您可以在模型中使用它。你用vqmod吗?尝试删除缓存文件。 也许为您的模型添加测试功能,看看您可以调用它。 你得到的错误是什么?
答案 2 :(得分:0)
您是否确实将文件放在catalog/model/account/children.php
中?如果是这样,你会得到任何有助于调试的错误消息吗?此外,当您运行代码时,您确定$data['children-name']
包含数据吗?