我遇到了一个奇怪的问题,我使用的是2.1版Codeigniter,问题是在config.php文件的第一行后面有空格 就在这段代码之后
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
长话短说我&#34;加入购物车&#34;如果之后有空格,按钮不起作用但是我试图通过
设置CI中的默认时间<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
date_default_timezone_set('Asia/Karachi');
它在本地服务器上工作正常,但在Live服务器上没有受到影响,即使在删除空格和默认时区后,实时版本的行为也是有线的,它不会将产品添加到卡上。
这是您可以检查的实时服务器版本
&#34; 在线购物车&#34;选项选择
&#34;的伯格斯&#34;选项选择
&#34; 添加到购物车&#34;它将重定向到&#34; 查看产品&#34;页面我不知道它是如何发生的。
这是链接:193.42.156.121/hk
视图中两个链接的代码段:
<li>
<a href="<?php echo site_url().'cart/fetch_product/'.$product->id; ?>" class="view">
Add to
<br>
Cart
</a>
</li>
控制器看起来像这样,视图发送其链接:
function add_to_cart($data='')
{
$product_id = $this->input->post('id');
$quantity = $this->input->post('quantity');
$post_options = $this->input->post('option');
if (!empty($data))
{
$product_id = $data['direct_product']->id;
$quantity = 1;
// print_r($data['product']);
// $data['product']->track_stock = $data['product']->track_stock = 0;
// echo $stock =$data['product']->track_stock ;
}
// Get a cart-ready product array
$product = $this->Product_model->get_cart_ready_product($product_id, $quantity);
// print_r($product);
// die();
//if out of stock purchase is disabled, check to make sure there is inventory to support the cart.
// echo $this->config->item('allow_os_purchase')." Purcahse allow <br>";
// echo (bool)$product['track_stock'].' Track stock <br>';
// die();
if(!$this->config->item('allow_os_purchase') && (bool)$product['track_stock'])
{
$stock = $this->Product_model->get_product($product_id);
//loop through the products in the cart and make sure we don't have this in there already. If we do get those quantities as well
$items = $this->go_cart->contents();
$qty_count = $quantity;
foreach($items as $item)
{
if(intval($item['id']) == intval($product_id))
{
$qty_count = $qty_count + $item['quantity'];
}
echo $qty_count."<br>";
}
if($stock->quantity < $qty_count)
{
//we don't have this much in stock
$this->session->set_flashdata('error', sprintf(lang('not_enough_stock'), $stock->name, $stock->quantity));
$this->session->set_flashdata('quantity', $quantity);
$this->session->set_flashdata('option_values', $post_options);
redirect($this->Product_model->get_slug($product_id));
}
}
// echo $this->config->item('allow_os_purchase')." Purcahse allow <br>";
// echo (bool)$product['track_stock'].' Track stock <br>';
// die();
// Validate Options
// this returns a status array, with product item array automatically modified and options added
// Warning: this method receives the product by reference
$status = $this->Option_model->validate_product_options($product, $post_options);
// print_r($status);
// die();
$start_time_in_24_hour = date("H:i", strtotime($this->setting['opening_time']));
$end_time_in_24_hour = date("H:i", strtotime($this->setting['closing_time']));
$timestamp = date("H:i", time());
if(
!($start_time_in_24_hour <= $timestamp && $end_time_in_24_hour <= $timestamp)
)
{
$this->session->set_flashdata('error', 'shop is closed');
redirect($this->Product_model->get_slug($product_id));
}
if( ! $status['validated'])
{
$this->session->set_flashdata('quantity', $quantity);
$this->session->set_flashdata('error', $status['message']);
$this->session->set_flashdata('option_values', $post_options);
redirect($this->Product_model->get_slug($product_id));
}
else
{
//Add the original option vars to the array so we can edit it later
$product['post_options'] = $post_options;
//is giftcard
$product['is_gc'] = false;
// Add the product item to the cart, also updates coupon discounts automatically
// print_r($product);
// die();
$this->go_cart->insert($product);
if (!empty($data))
{
$this->session->set_flashdata('message','Product added');
redirect('onlineOrder');
}
// go go gadget cart!
redirect('cart/view_cart');
}
// }
}
我在这个功能中获得的每个值都是正确的但不知道我的链接
http://193.42.156.121/hk/cart/fetch_product/56
被重定向到
http://193.42.156.121/hk/veggie-burger
它是怎么做到的?有什么想法吗?
答案 0 :(得分:0)
试试这样:
if(! ini_get('date.timezone')){
date_default_timezone_set('GMT');
}
这样,它不会改变config.php文件中的任何其他内容
答案 1 :(得分:0)
问题出在这里我是重定向到错误的链接,愚蠢我
if(!($start_time_in_24_hour <= $timestamp && $end_time_in_24_hour <= $timestamp))
{
$this->session->set_flashdata('error', 'shop is closed');
redirect($this->Product_model->get_slug($product_id));
}
应该是这样的:
if(!($start_time_in_24_hour <= $timestamp && $end_time_in_24_hour <= $timestamp) )
{
$this->session->set_flashdata('error', 'shop is closed');
redirect('onlineOrders');
}