0

CodeIgniter (バージョン 2.1.4) のショッピング カート クラスをいじり始めたばかりで、説明に役立つチュートリアルに従っています。しかし、何らかの理由で、カートに単純な配列を正常に追加できません。

これが私のカートクラスの実装です。

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

class Cart extends CI_Controller {

public function __construct() {
    parent:: __construct();
}

public function index() {
    $nav["navigation"] = $this->getCategory->getCategories();

    $this->load->view("header");
    $this->load->view("scripts"); 
    $this->load->view("nav", $nav);
    $this->load->view("cart");
    $this->load->view("footer");
}

function add() {
    $data = array(
        "id"        => "42",
        "name"      => "pants",
        "quantity"  => 1,
        "price"     => 19.99,
        "options"   => array("size" => "medium")
    );

    $this->cart->insert($data);
    var_dump($this->cart->contents()); //This should output the array!

}

function show() {

    $cart = $this->cart->contents();
    echo "<pre>" . print_r($cart) . "</pre>"; //Nothing here either!

}

function update() {

    $this->cart->update($data);
    redirect(base_url()."cart");

}

function total() {

    echo $this->cart->total();

}

function remove() {

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

}

function destroy() {

    $this->cart->destroy();

}

}

しかし、追加機能に行くと、var_dump は "array(0) { }" を表示するだけです。show 関数に移動しても同じ結果になります。

これは、カートライブラリがロードされたことを示すオートロード構成です。

$autoload['libraries'] = array("database", "session", "cart");

$autoload['helper'] = array("html", "url", "form");

私が見逃しているのは本当に単純で明白なものであることはわかっていますが、今のところ私は困惑しています。助言がありますか?

4

1 に答える 1

0

の配列キーのquantity名前が不適切です。挿入するデータでは、カートに保存するデータと同じように数量を指定する必要があります。qty

"qty"  => 1,
于 2013-09-27T16:56:19.850 に答える