this is for a listing-per-city type site (real estate etc)
i have three tables
--------------------------
states
cities
listings
relationships
----------------------------
state hasMany city
city hasMany listing
city belongsTo state
listing belongsTo city
in my default view i get this error when i try and pull information
from the state table:
Notice (8): Undefined index: State [APP/views/listings/index.ctp,
line 29]
it pulls just fine from the cities table and the listings table.
here are my model classes:
<?php
//models/listing.php
class Listing extends AppModel
{
var $name = 'Listing';
var $belongsTo = 'City';
}
?>
<?php
//models/city.php
class City extends AppModel
{
var $name = 'City';
var $belongsTo = 'State';
var $hasMany = 'Listing';
}
?>
<?php
//models/state.php
class State extends AppModel
{
var $name = 'State';
var $hasMany = 'City';
}
?>
----------------------------------------------------------
here is the relevant code in my VIEW //index.ctp
--------------------------
<?php foreach ($listings as $listing): ?>
<tr>
<td><?php echo $html->image( $listing['Listing']['thumb_url'],
array('alt' => 'Thumnbail'))?> </td>
<td><?php echo $listing['Listing']['id']; ?></td>
<td><?php echo $listing['Listing']['agent_id']; ?></td>
<td><?php echo $listing['Listing']['city_id']; ?></td>
<td><?php echo $listing['City']['city_name']; ?></td>
<td><?php echo $listing['City']['state_id']; ?></td>
<td><?php echo $listing['State']['state_name']; ?></td>
<td><?php echo $listing['State']['state_abbrev']; ?></td>
<td><?php echo $listing['Listing']['zip_code']; ?></td>
<td><?php // echo $listing['Listing']['city_name']; ?></td>
any time i reference $listing['State']['state_name'] or $listing
['State']['state_abbrev'] i get the error.
Notice (8): Undefined index: State [APP/views/listings/index.ctp,
line 29] and
Notice (8): Undefined index: State [APP/views/listings/index.ctp,
line 30]
the raw sql
------------------
Nr Query Error Affected Num. rows Took (ms)
1 DESCRIBE `listings` 8 8 1
2 DESCRIBE `cities` 3 3 1
3 DESCRIBE `states` 3 3 1
4 SELECT `Listing`.`id`, `Listing`.`agent_id`, `Listing`.`city_id`,
`Listing`.`listing_description`, `Listing`.`zip_code`,
`Listing`.`listing_features`, `Listing`.`thumb_url`,
`Listing`.`mainimage_url`, `City`.`id`, `City`.`city_name`,
`City`.`state_id` FROM `listings` AS `Listing` LEFT JOIN `cities` AS
`City` ON (`Listing`.`city_id` = `City`.`id`) WHERE 1 = 1 8
8 0
so it is selecting the right tables at first! any ideas guys?
thanks for your help
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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?hl=en
-~----------~----~----~----~------~----~------~--~---