dongtou9934 2012-08-27 17:02
浏览 60
已采纳

为什么CodeIgniter在模型I中创建了“调用未定义的方法”?

So I've been tasked with creating a function for our member database that will alert someone on a monthly basis as to when their membership is going to expire. We send out one email if a person is 6 months or less from their membership expiration, and another if they are 3 months out. No big whoop. I first create a model like this:

class Email extends CI_Model {

function __construct()
{
    parent::__construct();
}

// -----------------EMAIL-----------------
function emailMessage($message = 1,$recipient = 1777) { // Default "Test" Numbers
    $rInfo = $this->db->query("SELECT * FROM Members WHERE intKey = " . $recipient)->row();
    $eInfo = $this->db->query("SELECT * FROM Emails WHERE intKey = " . $message)->row(); 

    // Replacements?
    $bodyCopy = $eInfo->txtEmail;
    $bodyCopy = str_replace("[firstname]",$rInfo->strFirstName,$bodyCopy);  

    $this->load->library('email');
    $this->email->from('someone@example.com','John Q Public');
    $this->email->to($rInfo->strEmail); 
    $this->email->subject($eInfo->strTitle);
    $this->email->message($bodyCopy);
    $this->email->send();
    $this->email->clear();
}
}

All fine and good, and when I call this model from any other part of the site I have built, it works fine. It's a great way to handle any stock emails that have to be sent out to our constituency. Normally, it's just something like this within the code:

$this->load->model('email');
$this->email->emailMessage(8,$this->session->userdata('memberKey'));

Works like a charm. The big difference between where I've used it previously, and where I use it now is that I'm enclosing the call to the model within a loop as follows:

public function warningEmails() {
    $this->load->model('email');
    $sql = 'SELECT
                *, FLOOR(
                    DATEDIFF(dtAccreditationEnd, now())/ 30
                )AS diff
            FROM
                tblMembers
            WHERE
                enmAccredited = "yes"
            AND dtAccreditationEnd < DATE_ADD(now(), INTERVAL 6 MONTH)
            ORDER BY
                diff
    ';  
    $emailSend = $this->db->query($sql);
    foreach ($emailSend->result() as $row) {
        if ($row->diff <= 3) {
            $letter = 10;
        } else {
            $letter = 9;
        }
        $this->email->emailMessage($letter,$row->intMembersKey);
    }
}

It works great the first time through the loop, and fails with the following message the very next iteration through the loop:

Fatal error: Call to undefined method CI_Email::emailMessage() in /home/contract/public_html/members/application/controllers/staff.php on line 1033

Line 1033 is this line:

  $this->email->emailMessage($letter,$row->intMembersKey);

I there a problem where this model can only be called once in a given instance? What am I doing wrong? Thank you in advance for your assistance!

EDIT: I'm going to add a var_dump($this->email); to see what it could be...

object(CI_Email)#30 (46) { ["useragent"]=> string(11) "CodeIgniter" ["mailpath"]=> string(18) "/usr/sbin/sendmail"
["protocol"]=> string(4) "mail" ["smtp_host"]=> string(0) ""
["smtp_user"]=> string(0) "" ["smtp_pass"]=> string(0) ""
["smtp_port"]=> string(2) "25" ["smtp_timeout"]=> int(5)
["smtp_crypto"]=> string(0) "" ["wordwrap"]=> bool(true)
["wrapchars"]=> string(2) "76" ["mailtype"]=> string(4) "text"
["charset"]=> string(5) "utf-8" ["multipart"]=> string(5) "mixed" ["alt_message"]=> string(0) "" ["validate"]=>
bool(false) ["priority"]=> string(1) "3" ["newline"]=>
string(1) " " ["crlf"]=> string(1) " " ["send_multipart"]=>
bool(true) ["bcc_batch_mode"]=> bool(false) ["bcc_batch_size"]=> int(200) ["_safe_mode"]=> bool(false) ["_subject"]=> string(0) "" ["_body"]=> string(357) "Geoffrey,

This is a reminder that your PDCA Accreditation will expire in 3 months. Visit your Membership Dashboard to view all complete and incomplete course work at your convenience. The Membership Dashboard will assist you through the completion process. For more information, please contact Someone at Someone@example.com or 1-800-555-1212." ["_finalbody"]=> string(0) ""
["_alt_boundary"]=> string(0) "" ["_atc_boundary"]=> string(0) "" ["_header_str"]=> string(0) "" ["_smtp_connect"]=>
string(0) "" ["_encoding"]=> string(4) "8bit" ["_IP"]=>
bool(false) ["_smtp_auth"]=> bool(false) ["_replyto_flag"]=>
bool(false) ["_debug_msg"]=> array(0) { } ["_recipients"]=>
string(17) "recipient@example.com" ["_cc_array"]=> array(0) { } ["_bcc_array"]=> array(0) { } ["_headers"]=> array(5) { ["From"]=> string(54) ""Someone Example" " ["Return-Path"]=> string(28) "" ["Cc"]=> string(16) "copy@example.com" ["Bcc"]=> string(17) "blindcopy@example.com" ["Subject"]=> string(49) "=?utf-8?Q?PDCA_Accreditation_Expiration_Warning?=" } ["_attach_name"]=> array(0) { } ["_attach_type"]=> array(0) { } ["_attach_disp"]=> array(0) { } ["_protocols"]=> array(3) { [0]=> string(4) "mail" [1]=> string(8) "sendmail" [2]=> string(4) "smtp" } ["_base_charsets"]=> array(2) { [0]=> string(8) "us-ascii" [1]=> string(9) "iso-2022-" } ["_bit_depths"]=> array(2) { [0]=> string(4) "7bit" [1]=> string(4) "8bit" } ["_priorities"]=> array(5) { [0]=> string(11) "1 (Highest)" [1]=> string(8) "2 (High)" [2]=> string(10) "3 (Normal)" [3]=> string(7) "4 (Low)" [4]=> string(10) "5 (Lowest)" } }

  • 写回答

4条回答 默认 最新

  • dongsaohu6429 2012-08-27 18:02
    关注

    Try renaming the official email library to another one by doing so,

    $this->load->library('email', NULL, 'ci_email');
    

    Then access it by doing this,

    $this->ci_email->from('someone@example.com','John Q Public');
    

    The current email library has overwritten your email model.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c