我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');
难道我做错了什么?