Hello im trying to create a semi MVC project and im new to this so what ive done so far and what ill explain as my problem here may be completely bad on itself so sorry if that is the case.
- View 1 tables.phtml
- View 2 Calc.phtml
- View 3 Result.phtml
- Controller Tables.php
- Model Tables.php
On my first view is an Form where you input 2 numbers to generate an multiplication table and it puts this in an variable called $aTempArray
it looks like this:
Array (
[0] => Array ( [0] => 10 [1] => 6 [2] => 60 )
[1] => Array ( [0] => 7 [1] => 6 [2] => 42 )
[2] => Array ( [0] => 10 [1] => 6 [2] => 60 )
[3] => Array ( [0] => 7 [1] => 6 [2] => 42 )
[4] => Array ( [0] => 2 [1] => 6 [2] => 12 )
[5] => Array ( [0] => 1 [1] => 6 [2] => 6 )
[6] => Array ( [0] => 10 [1] => 6 [2] => 60 )
[7] => Array ( [0] => 6 [1] => 6 [2] => 36 )
[8] => Array ( [0] => 3 [1] => 6 [2] => 18 )
[9] => Array ( [0] => 5 [1] => 6 [2] => 30 )
)
On my second view it generates a form based on the array like this:
10 * 6 = ... <(this is a textbox)
7 * 6 = ... <(this is a textbox)
So when the user submits this second form on the second view I want it to OR send the $aTempArray
, OR generate a new one like this:
Array (
[0] => Array ( [0] => 10 [1] => 6 ['answer'] => ... )
[1] => Array ( [0] => 7 [1] => 6 ['answer'] => ... )
)
However, I have no clue on how to send the $aTempArray
becouse on the second submit it is empty becouse of the new controller/model that gets generated(or just reset becouse it reloads), and also I dont have a specific idea on how to get the sum data back when I submit the form on the second page. (the 10 * 6
for example becouse this is just text at this point.)
Ive tried a lot and found some things that do make this work but I want to know if there are better ways to do this.
- 1 is Saving the array in a session variable for example works but I want to avoid using sessions.
- 2 is making hidden input fields where I save the sums numbers without the answer like this:
<input type="hidden" name="rebuildArray" value="10,6/7,6 etc">
And to recreate the array I do something like:
- Str_split on
/
- Put in array
- str_split on
,
- Put this in arrays inside the main array.
- Foreach over every item in the array
-
if((currentsubarray[0] * currentsubarray[1]) == answersarray[currentpos])
Answer is correctelse
answer is not correct
So can someone say if one of these ways is a semi correct way to do it or give me a push in a direction on how to so this correctly in an MVC stylish way.
And again, I just started with MVC so if this is completely wrong in general im sorry.