I am new to cakephp. Thanks all in advance. I am using Cakephp2.8.5 version. I have a form with input fields and a submit button. When I am submitting a form, the input fields should pass through the array and should store in a variable called $totalData and I want to store the array variable $totalData in a session variable in cakephp. I have written code in the Userscontroller's cartData function. Please help me find out how to declare an array and store it in a session variable in cakephp.
My index.ctp page:
<form method="post" action="<?php echo $this->webroot ?>users/cartData?>"">
<table><thead>
<th>Exam Name</th>
<th>Venue Name</th>
<th>Date of Exam</th>
<th>Price / Course</th>
<th>Number of Exams</th>
<th>Add to Cart</th>
</thead>
<tbody>
<tr>
<td>
<select name="course">
<option value="">--Select--</option>
<option value="ITIL Foundation">ITIL Foundation</option>
<option value="PMP">PMP</option>
<option value="Prince 2 Foundation">Prince 2 Foundation</option>
</select>
</td>
<td><input type="text" name="venue" id="venue"></td>
<td><input type="text" name="Userdate" id="Userdate" ></td>
<td><input type="text" name="txtprice" id="Userdate" ></td>
<td>
<select name="num_exams">
<option value="">--Select--</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td>
<td><input type="submit" name="btnSubmit" value="Submit"></td>
</tr></tbody>
</table>
My `UsersController.php` page :
<?php
App::uses('CakeEmail', 'Network/Email');
class UsersController extends AppController
{
public function cartData()
{
if($this->request->is('post')|| $this->request->is('put'))
{
$totalData = array(
'exam' => $this->Form->input('course'),
'venue' => $this->Form->input('venue'),
'date' => $this->Form->input('Userdate'),
'price' => $this->Form->input('txtprice'),
'orders' => $this->Form->input('num_exams')
);
// I have a confusion how to store array values in session variable
$_SESSION['total_data'][] = $totalData;
}
}
}