【问题标题】:ERunactions is not working - YiiERunactions 不工作 - Yii
【发布时间】:2015-12-30 04:27:05
【问题描述】:

我正在尝试使用 Yii 扩展的 ERunactions 作为后台进程发送邮件,但它不起作用。

public function actionTimeConsumingProcess()
    {       
        ERunActions::touchUrl($this->createAbsoluteUrl('test/SendMail'),null,null,array());
}

SendMail 方法:

public function actionSendMail()
    {

          yii::import('application.extensions.smtpmail.PHPMailer');
        $mail = new PHPMailer(true);
        try{
        $dmmodel = DeliveryMethodModel::model()->findByPk(7);

        $mail->Host =$dmmodel->host;// "smtp.gmail.com";
        $mail->Username= $dmmodel->username;
        $mail->Password= $dmmodel->password;
        $mail->Mailer='smtp';
        $mail->Port=$dmmodel->port;
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = ($dmmodel->smtp_enableSSL==1?'ssl':($dmmodel->smtp_enableSSL==2 ? 'tls':''));


        $mail->From = $dmmodel->email_from;
        $mail->FromName = $dmmodel->name_from;       
        $mail->Subject    = "Mail Configuration : Test Mail";
        $mail->MsgHTML("This is an e-mail message sent automatically");
        $mail->AddAddress($dmmodel->email_from, $dmmodel->name_from);
        $mail->AddAddress($dmmodel->default_TO);

        $mail->IsHTML(true);  
     $mail->Send();
     // if(!$mail->Send()) {
            echo "Msg sent";
        //}else {
        }
        catch (phpmailerException $e)
        {
            echo "Mailer Error: " . $e->errorMessage();
       }    

    }

调用控制器动作的ajax代码,

$.ajax({
            type: 'POST',
            url: "<?php  echo  CController::createUrl('operator/TimeConsumingProcess'); ?>",  


            success: function(data){
}
});

application.log 中没有显示错误,请任何人帮助我为什么它不工作?

【问题讨论】:

  • 请谁能帮我解决这个问题

标签: jquery yii background yii-extensions


【解决方案1】:

您的代码不完整(就像 SendMail 中没有使用视图代码或模型),所以我不能说确切的问题是什么,但总的来说您的示例是有效的。

我能够在它的基础上组装一个小型的工作应用程序,希望它会有用。

你可以在github找到完整的代码。

控制器代码:

<?php

Yii::import('ext.runactions.components.ERunActions');

class TestController extends Controller
{

    /**
     * This is the default 'index' action that is invoked
     * when an action is not explicitly requested by users.
     */
    public function actionIndex()
    {
        Yii::log('action: Index', 'error');
        // renders the view file 'protected/views/site/index.php'
        // using the default layout 'protected/views/layouts/main.php'
        $this->render('index');
    }

    public function actionTimeConsumingProcess()
    {
        Yii::log('action: TimeConsumingProcess', 'error');
        ERunActions::touchUrl(
            $this->createAbsoluteUrl('test/SendMail'),null,null,array()
        );
        echo json_encode(array('status'=>'ok'));
    }

    public function actionSendMail()
    {
        Yii::log('action: SendMail', 'error');
    }

}

查看代码:

<h1>Welcome to the TEST PAGE</h1>

<p>Run the test <a class="run-test" href="#">run</a>.</p>

<script type="text/javascript">
$('.run-test').click(function() {
    alert('run');
    $.ajax({
        type: 'POST',
        url: "<?php  echo  CController::createUrl('test/TimeConsumingProcess'); ?>",
        success: function(data){
            alert(data);
        }
    });
});
</script>

代码的作用是:

  • 索引操作使用run 链接呈现index 视图
  • run 链接启动对test/TimeConsumingProcess 的 ajax 调用
  • actionTimeConsuminProcess 调用 actionSendMail
  • 所有操作都记录到应用程序日志文件protected/runtime/application.log

日志文件如下所示:

2016/01/13 00:51:48 [error] [application] action: Index
in /home/seb/web/yii-test-runactions/app/protected/controllers/TestController.php (14)
in /home/seb/web/yii-test-runactions/app/index.php (13)
2016/01/13 00:51:51 [error] [application] action: TimeConsumingProcess
in /home/seb/web/yii-test-runactions/app/protected/controllers/TestController.php (22)
in /home/seb/web/yii-test-runactions/app/index.php (13)
2016/01/13 00:51:51 [error] [application] action: SendMail
in /home/seb/web/yii-test-runactions/app/protected/controllers/TestController.php (31)
in /home/seb/web/yii-test-runactions/app/index.php (13)

你可以看到所有三个动作都被调用了。

另外请注意,SendMail 操作中有一些 echo 语句。除非您直接调用发送邮件操作(如 http://mysite/controller/sendmail),否则您不会看到它们。

您实际上可以这样做以确保发送邮件正常工作,但要与运行操作一起测试它,最好使用 Yii::log(...) 将调试数据保存在 application.log 中。

【讨论】:

    【解决方案2】:

    首先从上到下阅读所有代码,如果一切正常,然后尝试将相同的代码安装到另一个系统并安装新软件。

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多