CodeIgniter购物车奇怪的行为 [英] CodeIgniter Shopping Cart Strange Behaviour

查看:127
本文介绍了CodeIgniter购物车奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的行为CodeIgniter的购物车类。我已经在我的数据库中设置了ci_session表,并且已经将sess_use_database更改为TRUE。



发生的事情是,当我添加项目到购物车一切都很好:我看到我的总项目计数器上升和一切。当我去我的购物车页面,我第一次看到我的所有项目,在那里,他们应该是。我还提供了删除项目按钮和一个空车按钮。奇怪的事情发生在这里:当我点击删除一个项目,页面刷新(由于重定向我认为),但项目仍然存在!然后如果我手动刷新购物车的页面,我看到我删除的相同的项目消失。就像,当我使用重定向,我得到的页面的缓存,而不是实际页面上的新鲜信息。



无论如何,这里有一些链接:



尝试从本页添加一些项目:
http://www.pantanishoes.it/Niko/index.php/store / linea / urban
点击每个项目描述底部的大黑色按钮。



然后尝试在菜单上的Carrello并尝试删除一些项目或Svuota(这做一个简单的destroy()),看看会发生什么!任何帮助将非常感谢!



以下是购物车的一些代码。

  function add(){

$ item = $ this-> store_model-> get_item($ this-> input-> post('id'))

$ data = array(
'id'=> $ this-> input-> post('id'),
'name'=> $ item-> modello,
'qty'=> $ this-> input-> post('qty'),
'price'=> $ item-> prezzo,
'options'=> array(
'taglia'=> $ this-> input-> post('taglia'),
'linea'=> $ item- > linea,
'modello'=> $ item-> modello,
'foto'=> $ item-> foto1

);

$ this-> cart-> insert($ data);

$ linea = str_replace('',' - ',$ item-> linea);

redirect('/ store / linea /'。$ linea。'/','location');
}

function remove(){
$ rowid = $ this-> uri-> segment(3);
$ data = array(
'rowid'=> $ rowid,
'qty'=> 0
);

$ this-> cart-> update($ data);
redirect('cart');
}

function destroy(){
$ this-> cart-> destroy();
redirect('cart');
}

在localhost上一切正常工作!当我加载网站到服务器,它开始有这个问题。真的很奇怪!有没有一些配置的东西,我错过了?



Chrome说:
请求URL: http://www.pantanishoes.it/Niko/index.php/cart/remove/fb1b4a9869de6f24aa620e2307192d93
请求方法: GET
状态码:302暂时移动(来自缓存)

解决方案

所以我终于修复了这个小虫感谢我的一个朋友的帮助下,使用CI一段时间。正如你猜到的,这是一个缓存问题。你需要做的唯一的事情是强制PHP头像这样:

  header('Expires:Sat,26 Jul 1997 05 :00:00 GMT'); 
header('Last-Modified:'。gmdate('D,d M Y H:i:s')。'GMT');
header('Cache-Control:no-store,no-cache,must-revalidate');
header('Cache-Control:post-check = 0,pre-check = 0',false);
header('Pragma:no-cache');

您可以在控制器中执行私人功能,以便无法从外部访问,相对添加,删除,销毁方法。私有函数必须如下:

 私有函数_set_headers(){
header('Expires: 26 Jul 1997 05:00:00 GMT');
header('Last-Modified:'。gmdate('D,d M Y H:i(worry)')。'GMT');
header('Cache-Control:no-store,no-cache,must-revalidate');
header('Cache-Control:post-check = 0,pre-check = 0',false);
header('Pragma:no-cache');
}

你在其他函数中调用它:

  $ this-> _set_headers(); 

请记住,这只会在类的范围内工作。您不能在其他控制器中调用此函数,并且无法从范围外访问,因为它不是公共的。



感谢你们所有! p>

I have a really strange behaviour of CodeIgniter's Shopping Cart Class. I have set the ci_session table in my database and already have changed the sess_use_database to TRUE.

What is happening is that when i add items to the Shopping Cart everything is fine: i see my total items counter going up and everything. When i go to my shopping cart page the first time i see all my items there, where they should be. I have also provided delete item button and an Empty Cart button. The strange things happen here: when i click to remove an item, the page refreshes (due to the redirect i think) but the item is still there! Then if i manually refresh the page of the cart, i see that same item i had removed disappear. It's like, when i use redirect, i get the cache of the page, not the actual page with the fresh information on it.

Anyway, here are some links:

Try to add some items from this page: http://www.pantanishoes.it/Niko/index.php/store/linea/urban Clicking on the big dark button on bottom of every item description.

Then try to go to Carrello on the menu on top and try to delete some of the items or Svuota(which does a simple destroy()) and see what happens! Any help would be greatly appreciated! Thanks in advice!

Here is some code of the Cart.

function add() {

    $item = $this->store_model->get_item($this->input->post('id'));

    $data = array(
        'id' => $this->input->post('id'),
        'name' => $item->modello,
        'qty' => $this->input->post('qty'),
        'price' => $item->prezzo,
        'options' => array(
            'taglia' => $this->input->post('taglia'),
            'linea' => $item->linea,
            'modello' => $item->modello,
            'foto' => $item->foto1
            )
    );

    $this->cart->insert($data);

    $linea = str_replace(' ', '-', $item->linea);

    redirect('/store/linea/' . $linea . '/', 'location');
}

function remove() {
    $rowid = $this->uri->segment(3);
    $data = array(
        'rowid' => $rowid,
        'qty' => 0
    );

    $this->cart->update($data);
    redirect('cart');
}

function destroy() {
    $this->cart->destroy();
    redirect('cart');
}

On localhost everything was working great! When i loaded the website to the server, it started to have this issues. Really really strange! Is there some config thing I'm missing?

Chrome says: Request URL:http://www.pantanishoes.it/Niko/index.php/cart/remove/fb1b4a9869de6f24aa620e2307192d93 Request Method:GET Status Code:302 Moved Temporarily (from cache)

解决方案

Ok guys. So i finally fixed this little bug thanks to the help of a friend of mine who has used CI for a while. As some of you guessed, this is a cache problem. The only thing you need to do is to force PHP headers like so:

header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); 
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); 
header( 'Cache-Control: no-store, no-cache, must-revalidate' ); 
header( 'Cache-Control: post-check=0, pre-check=0', false ); 
header( 'Pragma: no-cache' );

You can do a private function in your controller so that it's not accessible from outside and call it in your relative add, delete, destroy methods. The private function must look something like this:

private function _set_headers() {
    header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); 
    header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i(worry)' ) . ' GMT' ); 
    header( 'Cache-Control: no-store, no-cache, must-revalidate' ); 
    header( 'Cache-Control: post-check=0, pre-check=0', false ); 
    header( 'Pragma: no-cache' );
}

And you call it inside the other functions like so:

$this->_set_headers();

Remember that this will work only in the scope of the class. You can't call this function in other controllers and it can't be accessed from outside the scope, cause it's not public.

Thanks to you all!!

这篇关于CodeIgniter购物车奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆