我正在使用cakephp 2.5.3,我正在控制器上发送两封邮件。
function coupon(){
$this->set('classType','comun cupon');
if(!empty($this->request->data)){
$data = $this->request->data;
$valid = false;
$errorMessage = 'Asegúrese de ingresar los datos correctamente';
$this->Paris->set($data);
if($this->Paris->validates()){
$valid = true;
}
if($valid){
$data['Paris']['coupon'] = strtoupper($data['Paris']['coupon']);
//Check if the coupon is free
$coupon = $this->Coupon->find('first',array(
'conditions' => array(
'Coupon.coupon'=> $data['Paris']['coupon'],
'AND'=>array(
'Coupon.registered' => 0
)
)
));
//$coupon = true;
if($coupon){
If the query worked then save the row and set registered field to 1
$this->Paris->save($data);
$q = "UPDATE coupons SET registered = 1 WHERE coupon = '{$data['Paris']['coupon']}' LIMIT 1";
if(is_array($this->Coupon->query($q))){
//Send the email
$parisEmail=new CakeEmail('paris');
$parisEmail->from(array($data['Paris']['email'] => 'Nuevo participante registrado - '. $data['Paris']['name'] . ' ' . $data['Paris']['surname']));
$parisEmail->viewVars(array('data'=>array(
$data['Paris']
)));
//$parisEmail->transport('Debug');
//Check whether it was sent or not
//FIRST EMAIL
if($parisEmail->send())
{
//Send the email
$parisUserEmail = new CakeEmail('parisUser');
$parisUserEmail->to(array($data['Paris']['email'] => $data['Paris']['name']));
$parisUserEmail->from(array($data['Paris']['email'] => $data['Paris']['name'] . ' ' . $data['Paris']['surname']));
$parisUserEmail->viewVars(array('data'=>array(
$data['Paris']
)));
//$parisUserEmail->transport('Debug');
//SECOND MAIL
if($parisUserEmail->send())
{
$this->Session->setFlash('<span style="color:#009900">Se realizó la inscripción exitosamente</span>','default',array('class'=>'flashMessage'));
}
}
else
{
$valid = false;
$errorMessage = 'No se pudo enviar el mail a su cuenta';
}
}else{
$valid = false;
$errorMessage = 'La inscripción no se pudo realizar, por favor intente nuevamente';
}
}else{
$this->Paris->validationErrors['coupon'] = 'El código de cupon es incorrecto o ya fue cargado';
$valid = false;
}
}
if(!$valid){
$this->Session->setFlash($errorMessage,'default',array('class'=>'flashMessage'));
}
}
}
是的,代码有点大,对不起。 现在,问题在于,我为这些电子邮件创建了两个模板:“paris.ctp”和“parisUser.ctp”。
第一封邮件发送正确...但是,当必须发送第二封邮件时,它会抛出此错误:
错误:确认您已创建文件:C:\ wamp \ www \ kirschbaumarg \ trunk \ app \ View \ Emails \ html \ paris_user.ctp
Notice: If you want to customize this error message, create app\View\Errors\missing_view.ctp
Stack Trace
•CORE\Cake\View\View.php line 468 → View->_getViewFileName(string)
•CORE\Cake\Network\Email\CakeEmail.php line 1684 → View->render(string, string)
•CORE\Cake\Network\Email\CakeEmail.php line 1537 → CakeEmail->_renderTemplates(string)
•CORE\Cake\Network\Email\CakeEmail.php line 1148 → CakeEmail->_render(array)
•APP\Controller\InfoController.php line 399 → CakeEmail->send()
•[internal function] → InfoController->coupon()
•CORE\Cake\Controller\Controller.php line 490 → ReflectionMethod->invokeArgs(InfoController, array)
•CORE\Cake\Routing\Dispatcher.php line 191 → Controller->invokeAction(CakeRequest)
•CORE\Cake\Routing\Dispatcher.php line 165 → Dispatcher->_invoke(InfoController, CakeRequest)
•APP\webroot\index.php line 108 → Dispatcher->dispatch(CakeRequest, CakeResponse)
如你所见,它要求“paris_user.ctp”。 谁能告诉我这里发生了什么?我通过将模板从“parisUser.ctp”重命名为“paris_user.ctp”来修复此问题...
我想理解为什么Cake会像这样......
答案 0 :(得分:0)
在Cake 2.x视图中,文件名仍以下划线分隔。这就是它的全部内容。您的第一个电子邮件工作的原因是它符合约定(通过单个单词全部小写)。
从书中可以看出:
查看模板文件以它们显示的控制器功能命名,以下划线形式。