2011-08-18 67 views
0

我正在使用symfony 1.4原則,而且我的項目出現問題。如何更新symfony中的現有記錄?一旦用戶點擊某個東西,如何更新現有記錄?

這是我的場景。在我的項目的後端應用程序中,當用戶將他/她的預訂表單發送到後端(我的項目是會議室預訂系統)時,管理員(負責處理後端應用程序)可以收到信息/記錄。如果他/她的請求被批准,管理員將通過電子郵件通知他/她,這是我沒事的=)。問題是我沒有想法,因爲我是symfony的新手,關於如果管理員點擊已批准的鏈接,如何從「待處理請求」(從請求批准)更改爲批准,反之亦然,如果點擊拒登按鈕。

我也有代碼它可以發送郵件(此代碼的作品除了更新記錄,以防萬一你可能會改變我的代碼) 有人可以幫我嗎?你能給我一些提示嗎?一些PHP代碼或symfony代碼?

apps/backend/modules/reservation/actions/actions.class.php 

<?php 

require_once dirname(__FILE__).'/../lib/reservationGeneratorConfiguration.class.php'; 
require_once dirname(__FILE__).'/../lib/reservationGeneratorHelper.class.php'; 

class reservationActions extends autoReservationActions 
{ 
    public function executeListApprove(sfWebRequest $request) 
    { 

    $reservation = $this->getRoute()->getObject(); 
    $reservation->approve(true); 


    $mailer = $this->getMailer()->composeAndSend(
     '[email protected]', 
     $reservation->getEmail(), 
     'Request Approval', 
     ' 
      Good Day. Hello This is Martin from the tech dept. 
     We have received your request.You can now use the 
     conference room due to your requested schedule. If 
     you have questions of your approval or your request, 
     Please contact me within 24 hrs. Thank you. 

     Martin 
     Junior Programmer 
     ' 
    ); 

     $this->getUser()->setFlash('notice', 'Sent mail approval:'); 
     $this->redirect('reservation/index'); 

    } 

    public function executeListDisapprove(sfWebRequest $request) 
    { 
    $reservation = $this->getRoute()->getObject(); 
    $reservation->Disapprove(true); 

    $mailer = $this->getMailer()->composeAndSend(
     '[email protected]', 
     $reservation->getEmail(), 
     'Request Disapproval', 
     ' 
      Good Day. Hello This is Martin from the tech dept. 
     We have received your request.Unfortunately, We 
     can\'t approve your request due: 
     1.Conflicts with the schedule. 
     2.Invalid request information. 
     If you have questions of your disapproval or your 
     request, Please contact me within 24 hrs. Thank you 

     Martin 
     Junior Programmer' 
    ); 



     $this->getUser()->setFlash('notice', 'Sent mail disapproval:'); 
     $this->redirect('reservation/index'); 

    } 
} 

回答

0

馬丁!

您應該在更改後保存對象。

$reservation->save(); 

提示:

  • 不要混合控制器層和視圖層,
  • 使用配置(app_yml)

    $reservation = $this->getRoute()->getObject(); 
    $reservation->approve(true); 
    $reservation->save(); 
    
    $mailer = $this->getMailer()->composeAndSend(
        sfConfig::get('app_email_sender'), 
        $reservation->getEmail(), 
        'Request Approval', 
        $this->getPartial('email_approve_body') 
    ); 
    
    $this->getUser()->setFlash('notice', 'Sent mail approval:'); 
    $this->redirect('reservation/index'); 
    
相關問題