Codeigniter:配置文件,使应用程序在实时和本地运行


Codeigniter: Config file making application behave wired in live and local

我遇到了一个奇怪的麻烦,我使用的是2.1版本的Codeigniter,问题是在config.php文件的第一行后有空格在代码

之后
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

长话短说我的"添加到购物车"按钮不工作,如果有空间之后,但我试图设置CI的默认时间通过做

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
date_default_timezone_set('Asia/Karachi'); 

它在本地服务器上工作得很好,但在实时服务器上更改没有影响,而且即使在删除空间和默认时区后,实时版本的行为也是有线的,它不会将产品添加到卡上。
这是服务器版,你可以去
查看"在线购物车"选项选择
"汉堡"选项选择
"添加到购物车",它将重定向到"查看产品"页面,我不明白它是如何发生的。
链接: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
    它是怎么做到的?你知道吗?

    试试:

    if(! ini_get('date.timezone')){
        date_default_timezone_set('GMT');
    } 
    

    这样就不会改变config.php文件

    中的任何内容

    问题在于这里我重定向到错误的链接,愚蠢的我

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