问题描述
的任务是创建一个带有异常类函数的单独文件,当满足某些条件时,该函数又会在另一个页面上调用。此实现纯粹用于记录这些有助于调试的异常。
我正在努力创建这个异常类并从检查函数传递参数,不确定这种方法是否最好。
在 /local/user_enrolment/classes/mod_exception_errors.PHP 我尝试按照 w3 学校的例子
namespace mod_modulename;
function exceptions($exception,$userid) {
//userid references a param in another function and file
echo "<b>Exception status is:</b> " . $exception->getMessage();
}
在发生用户检查的另一个文件中,我正在考虑按照这些方式做一些事情
public function checkuserexists($userid){
global $DB;
try {
if ($DB->record_exists('user_course',['id' => $userid])) {
/*this is the error/where i am currently stuck,trying to call the function from
local/user_enrolment/classes/mod_exception_errors.PHP
$exception = mod_modulename::class){
return the message and append level/status ie response should be
$exception->getMessage();
// Exception status is: 5 - user not found
*/
}
$user = $DB->get_record('user_course',array('id' => $userid));
if (!empty($user)) {
//check if user is active
if ($user->status === 'active') {
return $user->course_id;
}
$this->log_user_enrolled(sprintf(' local_new_enrolmentscheck_user: Mapping exists but not active'));
}
} catch(\Exception $e) {
$this-> local_new_enrolmentscheck_user($e->getMessage());
return false;
}
}
protected function local_new_enrolmentscheck_user($errormessage) {
error_log("Enrolment Error: $errormessage");
}
我希望这个问题是有道理的,这只是我对如何处理的想法,但不确定实现
TIA
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)