【问题标题】:In CAKEPHP Check content of all view and send mail if not ok在 CAKEPHP 检查所有视图的内容,如果不正常则发送邮件
【发布时间】:2018-11-16 09:11:37
【问题描述】:

使用 cakephp 2.9 我有这个需求:

我应该检查出现的页面上是否有特定的标签。

如果存在,不得做任何其他事情必须给我发电子邮件。

此时我想创建一个助手并调用 default.ctp

中的一个方法

类似:

$s = this-> fetch (‘content’);
$result_check = $this->myHelper->debug_content ($s); 
echo $s;

在myHelper函数中:

public function debug_content( $s) { 
  $pos = strpos ( $s, "<div class = \"box-body\">"); 
  if ( $pos === false) { echo “Error tag is not present!”; 
  return false; 
}

在AppController中:

public $helpers = array (…, ‘myHelper’);

到这里还可以……但是现在呢?

如何调用组件电子邮件(由我个性化)来发送电子邮件?

我在哪里称呼它?

你会怎么做?

谢谢,

最大

【问题讨论】:

    标签: cakephp cakephp-2.9


    【解决方案1】:

    我不知道你的问题是否正确。但是您可以在检查标签的函数中实现所需的电子邮件发送功能。

     App::uses('CakeEmail', 'Network/Email');
    
    public function debug_content( $s) { 
      $pos = strpos ( $s, "<div class = \"box-body\">"); 
      if ( $pos === false) { echo “Error tag is not present!”; 
     $Email = new CakeEmail();
     $Email->emailFormat('html');
     $Email->template('default');
     $Email->from('sending@adress.com');
     $Email->to('receiving@adress.com');
     $Email->subject('YOUR SUBJECT');
     $Email->send();
      return false; 
    }
    

    【讨论】:

      【解决方案2】:

      ImplementView.afterRenderFile 事件的侦听器,看看这是否解决了问题。查看View 类的源代码,you can see,该回调在调用View::render() 期间接收视图文件名和评估的内容。然后,您可以使用此侦听器检查您的标签的内容,并在必要时发送该电子邮件。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-21
        • 2019-08-20
        • 1970-01-01
        • 1970-01-01
        • 2019-01-20
        相关资源
        最近更新 更多