Suppose we have a table name employees in which a number of employees are there.
id |
Employee |
Age |
1 |
User1 |
23 |
2 |
User2 |
34 |
3 |
User3 |
22 |
4 |
User4 |
35 |
Now what we need to show this kind to table in our view.
we have to do following things:
1. We have to create a folder suppose Users in view folder name exact as controller .
2. Now inside the Employee folder you have to create a ctp file and name it anything you like suppose index. The file name will be index.ctp.
3. Now you have to go to controller folder and create a php file and name it exactly as folder functionname that you created in view that is UsersController.php
4. Now inside the EmployeeController.php file and write this code
<php
class UsersController extends AppController {
public function index() //name it exact as file created in view employee folder
{
$this->loadModel(Employee);//this is to load table name
$empl=$this->Employee->find(all);//this statement is nothing but select * from employee
$this->set(employee,$empl);
}
?>
5. Last step show the values in view.
<div>
<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr>
<?php Foreach($employee as $data)
{?>
<td>
<?php echo $data[Employee][id]?>
<td>
<td>
<?php echo $data[Employee][name]>
</td>
}
</tr>
<?php } >
</table>
</div>
Hope this will help you in understanding the core concept of cakephp.
0 Comment(s)