Hi,
Here is the controller code
<?php
class AdminController extends AppController
{
var $name = 'Admin';
var $layout='admin';
var $uses = array('State','Agent');
function agents_index()
{
$this->set('agents', $this->Agent->findAll());
}
}
?>
and here is the view (agents_index.thtml)
<h1>Agents</h1>
<table>
<thead>
<th>Name</th>
<th>Company Name</th>
<th>City</th>
<th>State</th>
<th>URL</th>
<th>Status</th>
<th></th>
</thead>
<tbody>
<?php
foreach($agents as $agent)
{
?>
<td><?php echo $agent['Agent']['contact_name'] ?></td>
<td><?php echo $agent['Agent']['company_name'] ?></td>
<td><?php echo $agent['Agent']['city'] ?></td>
<td><?php echo $agent['Agent']['state_id'] ?></td>
<td><?php echo $agent['Agent']['url'] ?></td>
<td><?php echo $agent['Agent']['approved'] ?></td>
<td>View Edit Delete</td>
<?php
}
?>
</tbody>
</table>
But the page shows the error :
Warning: Invalid argument supplied for foreach() in
/opt/lampp/htdocs/houseseeker/app/views/admin/agents_index.thtml on
line 15
and it does not show any recrods although there are records in the
table agents and also print_r($agents) also outputs nothing.
and line 15 is $this->set('agents', $this->Agent->findAll());
Any Ideas. How to make the controller access the records of the Agent
Model.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---