我有一个简单的控制器操作来创建一个Guest记录并呈现一个模板。
// First bind the form to our Guest:
$form->bind( $_POST, $guest );
// Validate and save, or show error messages
if( $form->isValid($_POST, $guest) ) {
if( $guest->save($_POST) ) {
$this->view->setMainView( 'confirm' );
}
}在我添加任何邮件之前,这一切都很好。但是,当我在Guest模型中添加一个事件处理程序来呈现模板时,控制器呈现的是白屏死亡,而不是我的确认模板。
在Guest模型中:
public function afterCreate() {
return GuestMailer::sendEmailConfirmation( $this );
}在GuestMailer类中:
public static function sendEmailConfirmation( $guest ) {
// create/configure $email message
$view = $guest->getDI()->get('simpleView');
$view->render( // Works without this call...
'confirmation_email',
array( 'guest' => $guest )
);
$content = $view->getContent();
$email->content( $content );
return $email->send();
}请注意,当我删除上述对render()的调用时,确认模板被成功呈现。
我以为Phalcon中的组件应该是高度解耦的?为什么渲染一个完全不同的模板会导致我的控制器的视图变得混乱?我怎样才能避免这种情况?
发布于 2015-04-16 18:26:35
我认为这个问题是由模板服务的特殊配置引起的,在正常的工作流中,它不会导致问题,当您需要“手动”呈现模板时,它们就会出现,就像您的情况一样,您可以参考链接的PhalconPHP论坛讨论,特别是链接锚引用的答案:http://forum.phalconphp.com/discussion/109/manually-render-separate-file-template-#C12015
https://stackoverflow.com/questions/29616814
复制相似问题