为什么重定向功能没有正确刷新页面?

时间:2017-12-28 15:33:36

标签: php redirect symfony1 symfony-1.2

我正在尝试将页面重定向回 general_faq_category 路由,但在重定向时,数据未正确加载。所以我手动刷新页面,然后正确加载数据(排序)。为什么页面不会自动刷新?它应该加载已排序的数据,但是当执行下面的 func 时它不会加载,但是在手动刷新路径后会出现更改。

以下是我用于重定向的代码

排序数据的功能:

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'));
        }
    }

来自actions.php的另一个Func

public function preExecute() {

        self::$formName = "FaqCategoryAdminForm";
        self::$modelPeer = "FaqCategoryPeer";
        self::$model = "FaqCategory";

        $this->redirectUrl = 'faq_category/index';
    }

查看代码:

<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&nbsp;&nbsp; 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')?>">&#9650;</a>
            <a href="<?=url_for('@drgug_faq_order?faqid=' . $row['id'] . '&direction=DOWN')?>">&#9660;</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>

0 个答案:

没有答案