【发布时间】:2015-11-02 03:34:44
【问题描述】:
我有一个类管理员用户,该用户有权修改用户数据。我想为这个方法添加两个或更多属性来完成所需的功能。
function update_user_by_admin($new_level, $user_id, $def_pass, $new_email, $active, $confirmation = "no", $staff_salary, $set_duty_timings) {
$this->user_found = true;
$this->user_access_level = $new_level;
$this->set_staff_salary=$staff_salary;
if ($def_pass != "" && strlen($def_pass) < 4) {
$this->the_msg = "Password is too short use the min. of 4 chars.";
} else {
if ($this->check_email($new_email)) {
$sql = "UPDATE %s SET access_level = %d, email = '%s', active = '%s', salary='salary'";
$sql .= ($def_pass != "") ? sprintf(", pw = '%s'", md5($def_pass)) : "";
$sql .= " WHERE id = %d";
$sql_compl = sprintf($sql, $this->table_name, $new_level, $new_email, $active, $user_id);
if (mysql_query($sql_compl)) {
$this->the_msg = "Data is modified for user with id#<b>".$user_id."</b>";
if ($confirmation == "yes") {
if ($this->send_confirmation($user_id)) {
$this->the_msg .= "<br>...a confirmation mail has been sent to the user.";
} else {
$this->the_msg .= "<br>...ERROR no confirmation mail is sent to the user.";
}
}
} else {
$this->the_msg = "Database error, please try again!";
}
} else {
$this->the_msg = "The e-mail address is invalid!";
}
}
}
如何在此处添加新的参数代码?
【问题讨论】:
-
您的代码看起来不完整,因为它不包含类定义。只需将另一个函数添加到您的类中以获得新方法。
-
我只想为这个方法添加两个属性,不需要继承,只是将参数从 html 表单元素传递给这个函数时遇到问题。我的判断是对的还是除此之外还有其他需要考虑的事情
-
您最初的问题是如何向类添加方法。然后您上面的评论询问如何向方法添加属性(没有意义)并且在传递参数时遇到问题。我认为您需要阅读类、方法、参数和参数的定义。如果(如我所料)您在问“如何向此函数/方法添加 2 个参数?”那么请改写问题。
-
尊敬的先生,我是编程新手,对 PHP 中的参数传递了解不多。如果您能解释如何将参数传递给函数,那将会更有帮助。我的意思是你的预期是非常正确的......
-
我已经为我现在认为是您的问题添加了答案。如果您可以更新此问题以反映您的实际要求,将会很有帮助。
标签: php class methods parameters