我编写了自己的Code Igniter模型来发送电子邮件.一切都很好,直到最近我才开始出现这个错误:
致命错误:无法在第2319行的/home/mysite/public_html/subdir/application/libraries/phpmailer/class.phpmailer.php中重新声明类phpmailerException
我正在使用:
CodeIgniter 2 PHPMailer 5.1
我尝试过以下方法来解决它:
这是我的控制器方法(公司/联系人),它调用我的模型(message_model):
function contact()
{
//Do settings.
$this->options->task='email';
$this->options->change = 'sent';
$this->options->form_validation='';
$this->options->page_title='Contact Us';
//Import library
include_once('application/libraries/recaptcha/recaptchalib.php');//Include recaptcha library.
//Keys for recaptcha, stored in mainconfig file.
$this->options->publickey = $this->config->item('recaptcha_public');
$this->options->privatekey = $this->config->item('recaptcha_private');
//Form validation
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('name_field','Name of problem','trim|required|min_length[3]|max_length[100]');
$this->form_validation->set_rules('desc_field','Description','trim|required|min_length[10]|max_length[2000]');
$this->form_validation->set_rules('email_field','Your email address','trim|required|valid_email');
$this->form_validation->set_rules('recaptcha_response_field','captcha field','trim|required|callback__check_recaptcha');
//If valid.
if( $this->form_validation->run() )
{
//Set email contents. …Run Code Online (Sandbox Code Playgroud) 我的错误是:
"Uncaught TypeError: ba is undefined"
"https://cdn.datatables.net/v/dt/dt-1.10.22/b-1.6.5/b-print-1.6.5/r-2.2.6/datatables.min.js:119"
Run Code Online (Sandbox Code Playgroud)
没有显示其他错误。我将 Jquery 放在列表中的第一位并检查了所有路径是否有效。我还从数据表站点获得了我认为最合适的链接。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Ajax Filter table</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.22/b-1.6.5/b-print-1.6.5/r-2.2.6/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.22/b-1.6.5/b-print-1.6.5/r-2.2.6/datatables.min.js"></script>
<script>
$(document).ready(function(){
$('#table').DataTable();
})
</script>
</head>
<body>
<div class="container">
<table class="table table-striped" id="table">
<tr>
<th>one</th>
<th>two</th>
<th>three</th>
<th>four</th>
</tr>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
<td>four</td>
</tr>
</table>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) (编辑:我已经意识到,或许在回调中将数组作为参数传递?)
我正在尝试研究如何将参数传递给CI中的回调函数.我已阅读文档,但除了以下内容之外没有太多内容:
要调用回调,只需将函数名称放在规则中,并使用"callback_"作为规则前缀.如果你需要在回调函数中接收一个额外的参数,只需在方括号之间的函数名之后正常添加它,如:"callback_foo [bar]",然后它将作为你的回调函数的第二个参数传递.
我要做的是创建一个回调函数,检查是否已经选择了一个本来不应该的.因此,如果有人选择"请选择"选项,则不会将其添加到数据库中.任务类型只是一个包含主键和名称字段以及大约10行的表.
控制器 所以这是我的控制器代码(减少):
function Add_Task()
{
$task_types_get = $this->task_model->Get_Task_Types();//Get available task types.
$this->options->task_types = $task_types_get->result();
$not_selectable = array(1);//Non selectable values for select. Added to callback function below for validation. These are pks.
$this->form_validation->set_rules("task_type","Task Types","required|callback__Not_Selectable[$not_selectable]");
if($this->form_validation->run())
{
//Add to db etc..
}
}
Run Code Online (Sandbox Code Playgroud)
回调 和我的回调检查是否有东西是不可选的:
function _Not_Selectable($option,$values=array())
{
if(in_array($option,$values))//Is the value invalid?
{
$this->form_validation->set_message('_Not_Selectable', 'That option is not selectable.');
return false;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
查看 从模型返回的数据是可以的,但没有验证错误.我的观点如下:
<? $this->load->view('includes/header'); ?>
<?=form_open();?>
<div class="form_row">
<div class="form_field">
<label for="task_desc">Task …Run Code Online (Sandbox Code Playgroud) codeigniter ×2
callback ×1
datatables ×1
javascript ×1
jquery ×1
parameters ×1
php ×1
phpmailer ×1