rxbanditboy1112 Posted July 17, 2008 Share Posted July 17, 2008 So I have a MVC for Events and Event Categories. I am trying to have the name of the category appear on the event page. I am associating events as belonging to event categories with a field called cat_id. I am able the retrieve the tables, but for some reason the event category part of the array ends up empty. Visually I am trying to make it look something like: Concert: Annual Event Where Concert is equal to a cat_name which is associated by cat_id(in the event table) = id(in the event categories table) and Annual Event is the event_title (in the event table). Getting data from the event table is no problem. I used print_r($event[0]) to show data from the first entry: Array ( [Event] => Array ( [id] => 6 [cat_id] => 1 [gallery_id] => 6 [event_title] => Miggs, Your Last Chance, Kyle Reece, The Strategy, PK, Kinderghost [event_date] => 2008-02-09 [event_hour] => 6 [event_minute] => 0 [event_ampm] => 1 [event_price] => 10.00 [event_tickets] => 6 [event_venue] => San Jose Skate [event_address] => 397 Blossom Hill Rd. [event_city] => San Jose [event_state] => CA [event_zip] => 95123 [event_caption] => This Event Will be Will Call bring your ticket for faster service though. Oh the rock will be endless, and the merriment will be a plenty. [event_body] => This Event Will be Will Call bring your ticket for faster service though. Oh the rock will be endless, and the merriment will be a plenty. [event_author] => 1 [event_read_count] => 1339 [event_h_story] => 1 [event_capacity] => 0 [amount_sold] => 0 [event_enabled] => 1 ) [EventCategory] => Array ( [id] => [cat_name] => [cat_description] => ) ) If you notice the EventCategory part of the array is empty for some reason.... Event Model: <?php class Event extends AppModel { var $name = 'Event'; var $hasOne = array( 'EventCategory' => array( 'className' => 'EventCategory', 'foreignKey' => 'id' ) ); } ?> Event Category Model: <?php class EventCategory extends AppModel { var $name = 'EventCategory'; var $hasMany = array( 'Event' => array( 'className' => 'Recipe', 'order' => 'Reciped } ?> Event Controller: <?php class EventController extends AppController { var $name = 'Event'; function index() { $this->set('event', $this->Event->findAll()); } } ?> Event Category Controller: <?php class EventCategoryController extends AppController { var $name = 'EventCategory'; function index() { $this->set('eventcategory', $this->EventCategory->findAll()); } } ?> Sorry, I know this is a bit lengthy, but I figured I would give a bunch of details rather than be vague. Hope someone can help. Link to comment https://forums.phpfreaks.com/topic/115312-cakephp-belongsto-associations-need-help-getting-data-from-another-table/ Share on other sites More sharing options...
awpti Posted July 18, 2008 Share Posted July 18, 2008 You should take this to the CakePHP forums/community site/mailing list for help. Or the appropriate third-party software forum. Link to comment https://forums.phpfreaks.com/topic/115312-cakephp-belongsto-associations-need-help-getting-data-from-another-table/#findComment-592942 Share on other sites More sharing options...
rxbanditboy1112 Posted July 18, 2008 Author Share Posted July 18, 2008 yeaaaaa, i've been trying to find a good place to post. It seems that there is a limited amount of resources for cake. Sometimes no results for some issues... Especially for this question. I have been stuck for the past 2 or 3 days with this issue. Although, i think after this it should be smooth sailing. Its just not grabbing the data from the table. I see the table and column names in the array but the result is blank. I don't get it. It happens in all versions of cake of me so i know it isn't a distro problem. I am gonna post else where also, but if anyone has used cake before here and knows what i am doing wrong let me know!! Link to comment https://forums.phpfreaks.com/topic/115312-cakephp-belongsto-associations-need-help-getting-data-from-another-table/#findComment-593029 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.