【发布时间】:2015-04-13 23:40:43
【问题描述】:
我有一个简单的控制器操作,它创建一个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 中的组件应该是高度解耦的?为什么渲染完全不同的模板会导致我的控制器视图混乱?我怎样才能避免这种情况?
【问题讨论】:
标签: phalcon