我在CodeIgniter中有一个名为"someclass"的库.
class someclass extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('email');
$this->load->database();
// $this->load-> library('database');
}
function email($naar=0,$onderwerp=0,$bericht=0){
if ($naar > 0 && $naar<10) {
$to = "tester@test.com"
//this is the part where it goes wrong
$CI =& get_instance();
$this->load->library('email');
//some one said that i needed ti assign the library's
$this->_assign_libraries();
$this->email->from('tester@test.com', 'test');
$this->email->to($to);
$this->email->subject($onderwerp);
$this->email->message("Test
bericht :
".$bericht);
$this->email->send();
// echo $this->email-> print_debugger();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: someclass::$email
Filename: libraries/someclass.php
Line Number: 139
Run Code Online (Sandbox Code Playgroud)
在我的视野中你可以有两种情况.
在这里,您可以创建一个名为sendEmail的方法
function sendEmail($naar=0,$onderwerp=0,$bericht=0)
{
$CI =& get_instance();
$CI->load->library('email');
//or autoload it from /application/config/autoload.php
$CI->email->from('tester@test.com', 'test');
$CI->email->to($to);
$CI->email->subject($onderwerp);
$CI->email->message("Test
bericht :
".$bericht);
$CI->email->send();
}
Run Code Online (Sandbox Code Playgroud)
在控制器中加载自定义库并使用调用id sendEmail(....)
您可以扩展本机电子邮件库类,并在该类中创建一个名为sendEmail的方法,例如:
class MY_Email扩展CI_Email {public function _ construct(){parent :: _construct(); 公共函数sendEmail().....等}
从您的控制器加载本机库类,$this->load->library('email')通过调用使用和发送您的电子邮件$this->email->sendEmail(...)
| 归档时间: |
|
| 查看次数: |
8252 次 |
| 最近记录: |