是否可以在模型中使用Codeigniter Email类?
我一直在尝试,但它拒绝加载邮件对象。一般来说,库是否允许加载到模型中?
代码
<?php
class ClubInvitation extends DataMapper {
var $table = "club_invitations";
var $has_one = array("club");
public function __construct($id){
parent::__construct($id);
$this->load->library('email');
}
public function inviteEmailToClub($email, $club, $message){
$invite = new ClubInvitation();
$invite->email = $email;
$invite->code = random_string('unique', null);
//$invite->save($club);
$club->ClubAdmin->limit(1);
$mainClubAdmin = $club->ClubAdmin->get()->User->get();
$data['club'] = $club;
$data['message'] = $message;
$data['club_leader'] = $mainClubAdmin;
$data['invite_code'] = $invite->code;
$email_body = $this->WBLayout->emailTemplate('invited_to_club', $data);
$this->email->from($mainClubAdmin->User->getAccount()->email, $club->name);
$this->email->to($email);
$this->email->subject($club->name.' has invited you to join');
$this->email->message($email_body);
$this->email->send();
}
}
1条答案
按热度按时间798qvoo81#
通常情况下,库被加载到控制器中,并从控制器中访问,而不是从模型中。你可以只将模型中的数据数组返回到控制器中,并从控制器本身使用电子邮件库。如果这对你来说不可行,那么试着这样做: