2015-06-15 33 views
0

首先对不起我的英文。带有POST值的PHP会话保存阵列

我有一个奇怪的问题,使用php $ _SESSION对象。 我花了2天没有找到解决方案。 我正在试图保存一个存储一些帖子值的多维数组。 我用这个值创建一个数组,然后创建一个包含这个数组的多维数组。

Page 1(多值数组中的setvalues保存会话) - > GET - > Page 2读取会话。

我的代码第1页:

首先,岗位值保存到一个对象的属性,并验证它们。

public function validateData(){ 

     $this->nombres=$_POST["nombre"]; 
     $this->imp_nombres=$_POST["imp_nombre"]; 
     $this->numeros=$_POST["numero"]; 
     $this->imp_numeros=$_POST["imp_numero"]; 
     $this->tallas=$_POST["talla"]; 
     $this->cantidades=$_POST["cantidad"]; 
     $this->productos=$_POST["products"]; 
     $this->equipos=$_POST["equipo"]; 


     if(WSI_Funtions::compareSizes($this->nombres,$this->imp_nombres,$this->numeros,$this->imp_numeros,$this->tallas,$this->cantidades,$this->productos,$this->equipos)) 
     { 
      $this->isValidModel=true; 
      $this->saveProductsValues(); 

     } 
     else{ 
      $this->isValidModel=false; 
      $this->errorMessage="Los datos no son correctos. Los parametros no coinciden"; 
     } 

} 

如果数据是好的,我保存这些值:

public function saveProductsValues() 
{ 


    $this->productsValues=array(); 
    $this->productsValues["names"]=$this->nombres; 
    $this->productsValues["imp_nombres"]=$this->imp_nombres; 
    $this->productsValues["numeros"]=$this->numeros; 
    $this->productsValues["imp_numeros"]=$this->imp_numeros; 
    $this->productsValues["tallas"]=$this->tallas; 
    $this->productsValues["cantidades"]=$this->cantidades; 
    $this->productsValues["productos"]=$this->productos; 
    $this->productsValues["equipos"]=$this->equipos; 


} 

然后我把它保存在一个会话:

public function saveSessionValues() 
{ 
    $_SESSION['customer'] = $this->customerObject; 
    $_SESSION['productsValues'] =$this->productsValues; 
    echo var_dump($_SESSION['productsValues']); 
} 

saveSessionValues回声打印:

array(8) { ["names"]=> array(12) { [0]=> string(0) "" [1]=> string(12) "ÁNGEL HDEZ." [2]=> string(11) "VUJASINOVIC" [3]=> string(4) "ABIA" [4]=> string(10) "MUTAKABBIR" [5]=> string(8) "PETROVIC" [6]=> string(5) "DOBOS" [7]=> string(4) "HOMS" [8]=> string(6) "CASTRO" [9]=> string(0) "" [10]=> string(0) "" [11]=> string(0) "" } ["imp_nombres"]=> array(12) { [0]=> string(0) "" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(1) "1" [4]=> string(1) "1" [5]=> string(1) "1" [6]=> string(1) "1" [7]=> string(1) "1" [8]=> string(1) "1" [9]=> string(0) "" [10]=> string(0) "" [11]=> string(0) "" } ["numeros"]=> array(12) { [0]=> string(1) "7" [1]=> string(1) "8" [2]=> string(1) "9" [3]=> string(0) "" [4]=> string(2) "11" [5]=> string(2) "12" [6]=> string(2) "18" [7]=> string(2) "19" [8]=> string(2) "22" [9]=> string(1) "5" [10]=> string(2) "33" [11]=> string(0) "" } ["imp_numeros"]=> array(12) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(0) "" [4]=> string(1) "1" [5]=> string(1) "1" [6]=> string(1) "1" [7]=> string(1) "1" [8]=> string(1) "1" [9]=> string(1) "1" [10]=> string(1) "1" [11]=> string(0) "" } ["tallas"]=> array(12) { [0]=> string(4) "XXXL" [1]=> string(3) "XXL" [2]=> string(2) "XL" [3]=> string(3) "XXL" [4]=> string(3) "XXL" [5]=> string(3) "XXL" [6]=> string(4) "XXXL" [7]=> string(3) "XXL" [8]=> string(2) "XL" [9]=> string(4) "XXXL" [10]=> string(2) "XL" [11]=> string(3) "XXL" } ["cantidades"]=> array(12) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(1) "1" [4]=> string(3) "145" [5]=> string(1) "1" [6]=> string(1) "1" [7]=> string(1) "1" [8]=> string(1) "1" [9]=> string(1) "1" [10]=> string(1) "1" [11]=> string(1) "1" } ["productos"]=> array(12) { [0]=> string(3) "109" [1]=> string(3) "109" [2]=> string(3) "109" [3]=> string(3) "109" [4]=> string(3) "109" [5]=> string(3) "109" [6]=> string(3) "109" [7]=> string(3) "109" [8]=> string(3) "109" [9]=> string(3) "109" [10]=> string(3) "109" [11]=> string(3) "109" } ["equipos"]=> array(12) { [0]=> string(7) "LEB ORO" [1]=> string(7) "LEB ORO" [2]=> string(7) "LEB ORO" [3]=> string(7) "LEB ORO" [4]=> string(7) "LEB ORO" [5]=> string(7) "LEB ORO" [6]=> string(12) "ES TALLA 4XL" [7]=> string(7) "LEB ORO" [8]=> string(7) "LEB ORO" [9]=> string(12) "ES TALLA 4XL" [10]=> string(7) "LEB ORO" [11]=> string(7) "LEB ORO" } } 

我的代码第2页(php标签ommitted):

if (!isset($_SESSION)) { session_start(); } 
echo var_dump($_SESSION['productsValues']); 

这种回声打印的下一个值:

array(8) { ["names"]=> NULL ["imp_nombres"]=> NULL ["numeros"]=> NULL ["imp_numeros"]=> NULL ["tallas"]=> NULL ["cantidades"]=> NULL ["productos"]=> NULL ["equipos"]=> NULL } 

第一级阵列存在,因为子阵列密钥进行打印,但是所有的第二级阵列是NULL ..

也许是使用$ _POST值? 我试图编码$ _POST对象的值,只保存一个JSON字符串,而不是保存具有相同结果的对象,JSON中的第一个节点是数组的键,但值为“NULL”

请帮忙吗? 谢谢!

+0

也许你需要从saveProductsValues() – valeriocomo

回答

2

你已经写完了这些值。尝试使用 -

$_SESSION['productsValues'][] = $this->productsValues; 
+0

返回一个数组伟大的!!!!!!!!!谢谢 !!!!!!! – user5010373

+0

欢迎.... :)。 –