2014-09-24 60 views
0

我有一个PHP文件中的类的数组,这个类有3个字段,我使用这些字段来保存SELECTS和INPUT CHECKBOX在FORM内部使用POST,然后我需要将这个类的数组发送到另一个用于处理数据的php文件。如何发送一个PHP数组类的值从一个PHP文件到另一个PHP文件

<?php 
    class info_subject{ 

    public $code_as; 
    public $time_as; 
    public $selectionn_as; 

     } 

    $subjects[0] = new info_subject();//The only way I have seen for creating an array of classes 
    //is with a for loop, but if you have a better way for doing this, please let me know  
    $subjects[1] = new info_subject(); 

    //here i am using the fields to save info in a form 

$i=0; 
echo "<form name = 'formsubjects' method='post' action='file2.php'>"; 
echo "<select name=\"".$subjects[$i]->time_as ."\">"; 
//options 
echo "</select>"; 
echo "<input type='checkbox' name=\"".$asignaturas[$i]->selection_as."\">"; 
//and so on with every position of the array using $i 
?> 

//then there is a button to send the the dato to file2.php 

//file2.php 
<?php 

$subjects=$_POST["$subjects"];//I am using this but i cant retrieve the fields of $subjects 

    ?> 

我该怎么办好友?

+2

你绝对应该看看MVC架构。 – 2014-09-24 01:08:24

+0

什么是好友?... – 2014-09-24 01:10:51

+0

一种编程方式,不会让你像HTML那样混合使用HTML,也就是说,它不能解决你的问题。对于你的问题,我建议你创建一个方法返回你需要的变量,然后在你的其他文件中使用你的类,并调用你刚刚实现的函数 – 2014-09-24 01:21:47

回答

0

$i=0; 
echo "<form name = 'formsubjects' method='post' action='file2.php'>"; 
echo "<select name=\"".$subjects[$i]->time_as ."\">"; 
//options 
echo "</select>"; 
echo "<input type='checkbox' name=\"".$asignaturas[$i]->selection_as."\">"; 

你可以尝试这样的:

$i=0; 
echo "<form name = 'formsubjects' method='post' action='file2.php'>"; 
echo "<select name=\"subjects[$i][".$subjects[$i]->time_as ."]\">"; 
//options 
echo "</select>"; 
echo "<input type='checkbox' name=\"subjects[$i][".$asignaturas[$i]->selection_as."]\">"; 

,然后在文件2

$subjects=$_POST["subjects"]; 

,并摘下你需要什么。

说实话,我觉得你的问题很难理解。也许尝试简化你的问题,并清理一些代码/格式,我们会更容易给你建议。

0

您不能通过$ _POST提交一个类或数组,因为post数组是一个只能包含简单值的数组。

+0

好的,我能做些什么来解决这个问题? – 2014-09-24 01:43:22

0

嗨〜Jose Ricardo Citerio。我希望你能读中国

我不知道你是不是需要这样,在文件1里面存储着选择的选项选项。然后文件2接收去后处理

<?php 

类info_subject {

public $code_as = ['name' => 'select_name', 'option' => ["k" => "v"]]; 
public $time_as; 
public $selectionn_as; 

}

$ subjects = new info_subject();

echo“”; echo'code_as [“name”]。 ' “>”'; //循环选项$ subject [“选项”]并打印k和v; like => foreach($ subjects-> code_as [“name”]为$ k => $ v){echo''。 $ v。 '';} echo“”; echo'xxx ['name']。 '“>请检查';

>

//然后有一个按钮发送的拿督到file2.php

//file2.php

<?php 
$subjects = $_POST["select_name"]; 
$subjects1 = $_POST["checkbox_name"]; 

?代替>

相关问题