Symfony 1.3: Any opinion about this code? Coud be shorter or better?
Posted
by user248959
on Stack Overflow
See other posts from Stack Overflow
or by user248959
Published on 2010-05-07T13:12:10Z
Indexed on
2010/05/08
20:48 UTC
Read the original article
Hit count: 192
symfony
|best-practices
Hi,
I need your opinion about this code below.
I have a list of messages: each message has a link that change the state of the message (read - non read).
In the partial "_message" i have this:
<div class="switching_link" id="switching_link_<?php echo $message ?>">
echo include_partial('link_switch_state', array('message' =>
$message))
</div>
In the partial "_link_switch_state" i have this:
if((int)$message->getState() == 1) {
$string_state_message="non read";
} else {
$string_state_message="read";
}
echo link_to_remote('Mark as '.$string_state_message, array(
'url' => 'message/switchState?id='.$message->getId(),
'update' => 'switching_link_'.$message,
"complete" => "switchClassMessage('$message');",
));
And in message/actions/actions.class.php i have this:
public function executeSwitchState(sfWebRequest $request) {
// searching the message we want to change its state.
$this->messages =
Doctrine::getTable('Message')->findById($request->getParameter('id'));
// changing the state of the message.
if($this->messages[0]->getState() == 1) {
$this->messages[0]->setState(0);
}
else {
$this->messages[0]->setState(1);
}
$this->messages[0]->save();
// rendering the partial that shows the link ("Mark as read/non
read").
return $this->renderPartial('mensaje/link_switch_state', array(
'message' => $this->messages[0]));
}
Regards
Javi
© Stack Overflow or respective owner