[英]FuelPhP: How can I add to a Session (Array/Map) Variable?
目前,我正在開發一個簡單的購物車應用程序。 我有一個接受項目用戶輸入(數量)的表格。 提交后,我將采取以下行動(僅是atm框架):
public function action_setquantity($flower_id) {
$doit = Input::post('doit');
$tf = Input::post('tf');
//$tf is ok (validated), create the cart data
$mycart[$flower_id] = $tf;
//This is only allowing 1 item to be written to Session var 'cart'
Session::set('cart', $mycart);
return Response::redirect("/show/cart"); }
現在,我的問題是創建數量/項目對的數組/映射。 就像現在的代碼一樣,每次用戶使用表單時,會話變量“購物車”將被覆蓋。 如何修復當前邏輯,以將映射連續添加到此Session變量。
您可以先簡單地獲取會話值,然后再添加該值,然后再重新分配它。
// Default to an empty array so we have a sensible value to work with.
$mycart = Session::get('cart', []);
// TODO: Modify cart data as required here.
// When done reassign the cart data to the session.
Session::set('cart', $mycart);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.