KKK
KKK

Reputation: 5

Yii: Already add or edit record but view not update

I got a problem about browser cache when I already add/edit record in database. The data in database changed but in view not change. I must press F5 in browser for refresh that page and it'll show updated data.

Please guide to me how to solve this problem, Thanks.

Sorry I forgot to told you guys, In my application has two part.

  1. Admin part (Backend) for add/edit data. (There's not any problem in this part)
  2. Front part for show data to viewer (Problem here! After add/edit record in Admin part, this part not changed. I must refresh page to see update)

This's my relevant code in Front part.

In Controller

class ProductController extends Controller
{
  public function actionIndex()
  {    
    $products = Product::model()->getProductList(); // use findAll() method
    $this->render('index', array('products' => $products));
  }
}

In Model

class Product extents CActiveRecord
{
  /*
   *
   * The other code that generated by Gii 
   *
   */

  public function getProductList()
  {
    return $this->findAll();
  }
}

In View

<html>
<body>

<ul class="thumbnails thumbnails-product">      
  <?php foreach ($products as $product): ?>

    <li class="span3" style="margin-left:0px;">
      <div class="thumbnail">
        <img class="img-thumb" src="../images/<?php echo $product->PDT_IMG" />
        <?php echo CHtml::link($product->PDT_NAME, array('product/view/' . $product->PDT_ID)); ?>                       

        <span class="price"><?php echo $product->PDT_PRICE; ?></span>

      </div>            
    </li>

  <?php endforeach; ?>
</ul>

</body>
</html>

Upvotes: 0

Views: 443

Answers (3)

KKK
KKK

Reputation: 5

The problem has been solved.

I just add

header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");

Everytime that view load, it'll reread page and doesn't keep any cache.

Upvotes: 0

Sudhanshu Saxena
Sudhanshu Saxena

Reputation: 1199

May be this can help you out: Real-time display of server push data using Server-Sent Events (SSE)

this is server push technique by which we can fetch data in every changes made automatically and also after a certain time.

Upvotes: 0

Highmastdon
Highmastdon

Reputation: 7530

If you want something to update on-the-fly, I think you're looking for in place editing.
You could take a look at this extension which does that for you.
Especially this part.

enter image description here

Upvotes: 1

Related Questions