无法理解为什么在空控制器/管理员/管理员上调用成员函数 send_notification(.php 112"



我从在线保护程序收到错误,但在本地主机中没有出现。

来自在线保护程序的错误是

Severity: error --> Exception: 
Call to a member function send_notification() on null controllers/Admin.php 112

我想使用此代码向我的客户发送消息。

这是一个控制器,管理员.php。

function notification($param1 = '', $param2 = '') 
{
if ($param1 == 'create') 
{
$notification_code = $this->crud_model->create_notification();
$check_notification_to_send = $this->input->post('check_notification');
if ($check_notification_to_send == 1) {
$data['title']     = $this->input->post('title');
$customers  = $this->db->get('customer')->result_array();                
$date           = date("d M,Y");
$message  = $data['title'] . ' ';
$message .= get_phrase('for more details please login to your  acc'). ' ';
$message .= get_phrase('published on') . ' ' . $date;
foreach($customers as $row) {
$reciever_phone = $row['phone'];
//This is the line 112 on which error originate
$this->notification_model->send_notification($message , $reciever_phone);
}
}
}
}

这是notification_model。

function send_notification($message = '' , $reciever_phone = '') {
set_time_limit (0);
require_once(APPPATH . 'libraries/twilio_library/Twilio.php');

$accnt_sid    = $this->db->get_where('settings', array('type' => 'accnt_sid'))->row()->description;
$auth_token     = $this->db->get_where('settings', array('type' => 'auth_token'))->row()->description;
$client         = new Services_Twilio($accnt_sid, $auth_token); 
$client->account->messages->create(array( 
'To'        => $reciever_phone, 
'From'      => $this->db->get_where('settings', array('type' => 'sender_phone_number'))->row()->description,
'Body'      => $message   
));
}

这是视图目录中的表单

<div class="col-sm-8">
<input required="" type="text" class="form-control" name="title">
</div>
<div class="form-group has-warning">
<label class="col-sm-3 control-label"><i class="fa fa-bell-o"></i><?php echo get_phrase('send_sms');?></label>            
<div class="col-sm-5">
<select required="" class="form-control" name="check_notification">
<option value=""><?php echo get_phrase('select');?></option>
<option value="1"><?php echo get_phrase('yes');?></option>
<option value="2"><?php echo get_phrase('no');?></option>
</select>
</div>                
</div>

您必须使用以下方法在控制器中加载模型:

$this->load->model('notification_model');,您将能够在控制器中调用该函数。

只要确保, 使用public声明模型函数

所以它会像:

public function send_notification($message = '' , $reciever_phone = '')

相关内容

最新更新