I am trying to redirect the page back to general_faq_category route but when it is redirected the data is not loaded correctly. So i manually refresh the page and then the data is loaded correctly (sorted). Why is the page not refreshing automatically? It should load the data sorted but it isn't loading when the below func is executed, however after manually refreshing the route the changes appear.
The following is the code i used for redirecting
Function for sorting data:
function executeFaqCategoryOrder(sfWebRequest $request) {
$faqid = $request->getParameter('faqid');
$direction = $request->getParameter('direction');
if ($faqid & $direction) {
$c = new Criteria();
$c->add(FaqCategoryPeer::ID, $faqid);
$current_faq = FaqCategoryPeer::doSelectOne($c);
$current_order = $current_faq->getOrder();
switch ($direction) {
case 'UP':
$c = new Criteria();
$c->add(FaqCategoryPeer::ORDER, $current_order - 1);
$previous_faq = FaqCategoryPeer::doSelectOne($c);
$current_faq->setOrder($previous_faq->getOrder());
$current_faq->save();
$previous_faq->setOrder($current_order);
$previous_faq->save();
$this->redirect($this->generateUrl('general_faq_category'));
break;
break;
case 'DOWN':
$c = new Criteria();
$c->add(FaqCategoryPeer::ORDER, $current_order + 1);
$next_faq = FaqCategoryPeer::doSelectOne($c);
$current_faq->setOrder($next_faq->getOrder());
$current_faq->save();
$next_faq->setOrder($current_order);
$next_faq->save();
$this->redirect($this->generateUrl('general_faq_category'));
break;
break;
default:
$this->redirect($this->generateUrl('general_faq_category'));
break;
}
$this->redirect($this->generateUrl('general_faq_category'));
}
}
Another Func from actions.php
public function preExecute() {
self::$formName = "FaqCategoryAdminForm";
self::$modelPeer = "FaqCategoryPeer";
self::$model = "FaqCategory";
$this->redirectUrl = 'faq_category/index';
}
View Code:
<div class="pagead">
<div class="pagein"align="center">
<div align="center">
<h3>FAQ Category (Total: <?php echo $total ?>)</h3>
<span style="float: right;">
<a href="<?php echo url_for('faq/index') ?>" title="Back to FAQs">Back</a> |
<a href="<?php echo url_for($sf_params->get('module') . '/new') ?>" title="Click to add new category">New FAQ Category</a>
</span>
</div>
<br/>
<div align="center"><?php $pager->render() ?></div>
<table width="100%" id="category">
<tr>
<th width="30%">Name</th>
<th width="15%">Created At</th>
<th width="5%">Order</th>
<th width="12%">Action</th>
</tr>
<?php foreach ($pager->getResults() as $row): ?>
<tr id="category_<?php echo $row['id'] ?>" class="categories">
<td align="center"><?php echo $row['name']; ?></td>
<td align="center"><?php echo date(sfConfig::get('app_display_alternate_format_for_date'), strtotime($row['created_at'])); ?></td>
<td>
<a href="<?=url_for('@drgug_faq_order?faqid=' . $row['id'] . '&direction=UP')?>">▲</a>
<a href="<?=url_for('@drgug_faq_order?faqid=' . $row['id'] . '&direction=DOWN')?>">▼</a>
</td>
<td align="center">
<?php echo link_to(image_tag("/images/edit.png", array("title" => "Click to modify category")), $sf_params->get('module') . '/edit?id=' . $row['id']); ?>
<?php echo link_to(image_tag("/images/cross.png", array("title" => "Click to delete category")), $sf_params->get('module') . '/delete?id=' . $row['id'], array('confirm' => 'All related records will be deleted, are you sure ?')); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<br/>
<br/>
</div>
<div class="bot"></div>