Symfony1 symfony getPartial不存在

Symfony1 symfony getPartial不存在,symfony1,Symfony1,我的actions类中有一个私有函数sendmail private function sendEmail($args) { $mailer = sfContext::getInstance()->getMailer(); $message = $this->getMailer()->compose(); $address = $this->getFromAddress(); $message->setFrom(array($addr

我的actions类中有一个私有函数
sendmail

private function sendEmail($args)
{
    $mailer = sfContext::getInstance()->getMailer();
    $message = $this->getMailer()->compose();
    $address = $this->getFromAddress();
    $message->setFrom(array($address['email'] => $address['fullname']));
    $message->setTo('blah@blah.com');
    $message->setSubject('Subject');
    $message->setBody($this->getPartial('emailTemplate', array('args' => $args)), 'text/html');
    $this->getMailer()->send($message);
}
我从我的
寄存器调用该函数
操作:

public function executeRegister(sfRequest $request)
    {
        sfConfig::set('app_sfForkedApply_from', array(
            'email' => 'blah@blah.com',
            'fullname' => 'fullname'
        ));

        //code for registering

              try {
                    // send email
                    $this->sendEmail($args);
               }
                catch (Exception $e) {
                    $this->logMessage('Email not sent: ' . $e->getMessage(), 'err');
                }

                $out = array('status' => 'success', 'args' => args);
            }            
        }

        $this->getResponse()->setContentType('application/json');
        $this->getResponse()->setContent(json_encode($out));

        return sfView::NONE;
    }
现在,我想从不同的操作调用
sendmail
函数,在同一操作类中调用
Register2

public function executeRegister2(sfRequest $request)
    {
        sfConfig::set('app_sfForkedApply_from', array(
            'email' => 'blah@blah.com',
            'fullname' => 'fullname'
        ));

        //code for registering #2

        if ($var = true) {
            try {

                // sending different email
                $this->sendVerificationMail($args);

                $out = array(
                    'status' => 'success',
                    'message' => 'Verification email sent'
                );
            }
            catch (Exception $e) {
                $this->logMessage('Verification email not sent: ' . $e->getMessage(), 'err');

                $out = array(
                    'status' => 'error',
                    'message' => 'Verification email not sent: ' . $e->getMessage()
                );
            }
        }
        else {
            //do other stuff

            $out = array(
                'status' => 'success',
                'message' => 'User activated'
            );
        }

     //added following try-catch to send new email but its not working
        try {
            // send email
            $this->sendEmail($args);

        }
        catch (Exception $e) {
            $this->logMessage('Email not sent: ' . $e->getMessage(), 'err');
        }

        $this->getResponse()->setContentType('application/json');
        $this->getResponse()->setContent(json_encode($out));

        return sfView::NONE;
    }
寄存器
操作,它工作。
寄存器2
操作,它返回以下错误:

Email not sent: The template "_emailTemplate.json.php" does not exist or is unreadable in "".  
如果我从一个操作调用函数而不是从另一个操作调用函数,它怎么会找到模板呢?

它是否总是将模板转换为json文件?这可能是问题所在吗?

sfView
使用您的请求格式获取模板的名称。因此,如果您的操作
executeRegister2
是Json,它将查找
.Json.php
文件

您可以通过sendMail方法作弊:

private function sendEmail($args)
{
    $mailer = sfContext::getInstance()->getMailer();

    // Added
    $request = sfContext::getInstance()->getRequest();
    $format  = $request->getRequestFormat();
    $request->setRequestFormat('html');


    $message = $this->getMailer()->compose();
    $address = $this->getFromAddress();
    $message->setFrom(array($address['email'] => $address['fullname']));
    $message->setTo('blah@blah.com');
    $message->setSubject('Subject');
    $message->setBody($this->getPartial('emailTemplate', array('args' => $args)), 'text/html');
    $this->getMailer()->send($message);

    // Revert the request format
    $request->setRequestFormat($format);
}

这应该可以做到(也就是说,在发送请求时发送电子邮件可能需要时间,并且会弄乱您的请求格式:让它们异步的另一个原因).

你能给我们看一下
getPartial
的内容吗?它不应该有什么区别,因为问题不在那里,因为它是从一个不同的毫无意义的动作开始工作的。我们没有与错误消息相关的代码,也没有足够的信息来帮助您解决问题。您想要我的电子邮件模板的内容吗?我只是添加了更多代码。也许这会有帮助??工作起来很有魅力!!谢谢你为我节省了很多时间!!