doutang7707 2015-01-06 18:15
浏览 113

重定向回同一页面时CakePHP缓存问题

I'm using CakePHP 2.6

I'm having a problem when I redirect back to the same view from where the request was made. The view seems to be cached, so whatever changes were made during the request are not shown until the page is refreshed again.

This means:

  1. the user can't see the changes just made.
  2. Flash messages are shown on the following view (which is bad).

Why is this happening?

Things I've checked:

  • My PHP environment has caching turned off
  • My CakePHP configurations are the defaults (see below).
  • Caching should be disabled because I'm in debug mode: Configure::write('debug', 2);
  • I'm testing in multiple browsers with and without browser caching enabled.

Configure::write('Session', array( 'defaults' => 'php' ));

Representative example:

    //Inside ListingsController...

    $this->Listing->id = $id;
    if ($this->Listing->save($listing)) {
        $this->Flash->success(__('"%s" is now active.', $listing['Listing']['title']));
    } else {
        $this->Flash->error(__('Problem activating'));
    }
    //this is the original view...
    $this->redirect( array('controller'=>'listings', 'action'=>'mylistings') ); 
  • 写回答

2条回答 默认 最新

  • douyi3632 2015-01-09 09:44
    关注

    Try this it redirects to the referer

    $this->Listing->id = $id;
    if ($this->Listing->save($listing)) {
        $this->Flash->success(__('"%s" is now active.', $listing['Listing']['title']));
        // Redirect the referer
        $this->redirect(
            $this->referer()
        );
    } else {
        $this->Flash->error(__('Problem activating'));
    }
    

    Thanks..!

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?