how to update the existing record once the user clicks on something?
I'm using symfony 1.4 doctrine and I was having a problem on my project. How to update a existing record in symfony?
Here's a my scenario. On my backend application of my project, the admin(who handles the backend application) can recieved info/record when the user send his/her reservation form to the backend(my project is conference room reservation system). the admin will notify him/her through email if his/her request is approved or not which I got all right =). The problem is I have no Idea since I'm new to symfony on how to change from the "pending request"(from the request approval) into approved if the admin clicks on the approved link or vice versa if disapprove button was clicked.
I also have code It can send mails( this code works except for updating the record, just in case you might change something on my co开发者_Go百科de) Can someone help me? Can you give me some tips? some php code or symfony code?
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(
'supervisor@teleserv.local',
$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(
'supervisor@teleserv.local',
$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');
}
}
Martin!
You should to save object after changes.
$reservation->save();
Tip:
- Do not mix controller layer and view layer,
Use configurations (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');
精彩评论