Call to a member function on a non-object Issue |
I want to put all my email send code from a library.
i have craeted a controller function resetPassword controller is forgot_password.php public function resetPassword() { //Reset Password Send Mail Code Here $this->load->helper('form'); $this->load->library('form_validation','security'); $this->form_validation->set_rules('email', 'Email address', 'trim|required|valid_email'); if ($this->form_validation->run() == FALSE) { $message = array('type' => 'alert', 'text' => 'Please submit valid email !', 'title' => 'ERROR'); } else { $this->load->model('login_model'); $email = $this->input->post('email'); $email = $this->security->xss_clean($email); $user_exists = $this->login_model->where('user_username', $email)->get(); if($user_exists) { $params = array( 'user_username'=>'hjsjajdjaa', 'link'=> 'link' ); $this->load->library('backendEmailLibrary'); $responseFromMail = $this->backendEmailLibrary->sendResetPasswordMail($params); if($responseFromMail) echo 'success'; } } else { echo 'faliure'; } } echo 'exit'; } my library <?php defined('BASEPATH') OR exit('No direct script access allowed'); class BackendEmailLibrary { protected $CI; // Constructor public function __construct() { $this->CI =& get_instance(); $this->CI->load->model('login_model'); if (ENVIRONMENT == 'production') { $config = Array( 'protocol' => 'sendmail', 'smtp_host' => 'your domain SMTP host', 'smtp_port' => 25, 'smtp_user' => 'SMTP Username', 'smtp_pass' => 'SMTP Password', 'smtp_timeout' => '4', 'mailtype' => 'html', 'charset' => 'iso-8859-1' ); } else $config = Array(); } public function sendResetPasswordMail($params) { $user_username = $params['user_username']; $token_link = $params['token_link']; $subject = 'password reset mail'; echo '<pre>'; print_r($config); die; $this->CI->load->library('email', $config); if(!empty($config)) { //Reset Mail starts $this->CI->email->set_newline("\r\n"); $this->CI->email->from('[email protected]', 'xxxx'); $user_exists = $this->CI->login_model->where('user_username', $user_username)->get(); $data = array( 'pssrestmailName'=> $user_exists->user_fname, 'pssrestmailToken'=> $link ); $this->CI->email->to($user_exists->user_username); // replace it with receiver mail id $this->CI->email->subject($subject); // replace it with relevant subject $body = $this->CI->load->view('emails/resetpassword.php',$data,TRUE); $this->CI->email->message($body); $flag = $this->CI->email->send(); return $flag; } else return false; } } ===================================================== I dont knw where from the error is coming from ? Please help Severity: Notice Message: Undefined property: Forgot_password::$backendEmailLibrary Filename: controllers/forgot_password.php Call to a member function sendResetPasswordMail() on a non-object in forgot_password.php on line Bolded area.
08-06-2016, 03:48 AM
(This post was last modified: 08-06-2016, 03:50 AM by InsiteFX. Edit Reason: fix speeling errors )
Available Visibility in PHP Classes
There are 3 types of visibility available in php for controlling your property or method. 1) Public: Public method or variable can be accessible from anywhere. I mean from inside the class, out side the class and in child(will discuss in next chapter) class also. 2) Private: Method or property with private visibility can only be accessible inside the class. You can not access private method or variable from outside of your class. 3) Protected: Method or variable with protected visibility can only be access in the derived class. Or in other word in child class. Protected will be used in the process of inheritance. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(08-06-2016, 03:48 AM)InsiteFX Wrote: Available Visibility in PHP Classes Fixed ! Thanks For your help ![]() |
Welcome Guest, Not a member yet? Register Sign In |