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

时间:2011-08-12 12:37:04

标签: static call yii instance

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

$this->renderPartial(string $fileNameToRenderData, bool $wheaterToReturnOrEchoDirectly);

静态地,像这样:

GodForbiddenClassName::renderPartial(string $fileNameToRenderData, bool $wheaterToReturnOrEchoDirectly);

4 个答案:

答案 0 :(得分:21)

您可能希望查看我在自定义类函数中使用过的renderInternal等。它可以被称为:

$ccc = new CController('context');
$html = $ccc->renderInternal($view_file_string, array('data'=>$data), true);

答案 1 :(得分: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();
    }

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

答案 2 :(得分:4)

似乎这是不可能的,因为渲染是代表控制器(或后继者CBaseController)执行的表示

但是,在控制台应用程序模式中,您可以使用:

CConsoleCommand->renderFile()

请参阅http://www.yiiframework.com/doc/api/1.1/CConsoleCommand

答案 3 :(得分:1)

我写的{p> Check this yii wiki article .. :)

====>>> $ emailTemplate = $ this-> renderPartial(' template / templatecontact',array(),true); //获取电子邮件模板内容