HowTo:调用方法:renderPartial() - 静态?

9 static call instance yii

如何在Yii Framework中调用此方法:

$this->renderPartial(string $fileNameToRenderData, bool $wheaterToReturnOrEchoDirectly);
Run Code Online (Sandbox Code Playgroud)

静态地,像这样:

GodForbiddenClassName::renderPartial(string $fileNameToRenderData, bool $wheaterToReturnOrEchoDirectly);
Run Code Online (Sandbox Code Playgroud)

ldg*_*ldg 21

您可能希望查看我在自定义类函数中使用的renderInternal等.它可以像:

$ccc = new CController('context');
$html = $ccc->renderInternal($view_file_string, array('data'=>$data), true);
Run Code Online (Sandbox Code Playgroud)


Ars*_*Ali 9

我必须在模型中使用render partial,我有这样的代码

    public function sendEmail(){
        $emailTemplate = new EmailTemplate();
        $message = $emailTemplate->getEmailTemplate(EmailTemplate::AGENT_CONTACT_REFFER);
        $message = $emailTemplate->replaceConstantWithValues($this->agent,$message);
        $message = $emailTemplate->replaceConstantWithValues($this->contact,$message);
        //$message = $emailTemplate->replaceConstantWithValues($this->contact->notes,$message);
        $message = str_replace("[CONTACT_NOTES]", Yii::app()->controller->renderPartial('application.views.note._notes', array('notes'=>$this->contact->notes,'showLinks'=>false),true),$message);
        $message = $emailTemplate->replaceConstantWithValues($this,$message);

        $email = Yii::app()->email;
        $email->from = $this->referringAgent->email;
        $email->to = $this->agent->email;
        $email->subject = "An agent has referred a contact to you";
        $email->message = $message;
        $email->send();
    }
Run Code Online (Sandbox Code Playgroud)

这里我使用了Yii :: app() - > controller-> renderPartial

  • 这仅在存在控制器时才有效.如果您尝试使用此功能从cron作业或控制台应用程序发送电子邮件,则此操作将失败. (3认同)