Sunday, February 5, 2012

Using Join Tables in Cakephp - result in view.ctp

Hi,

I have looked, search and founded, but not the answer to my questions:
How do I get the result of my join table in my view.ctp? Am I doing
something wrong?

I have followed some guides from bakery and other blogs, and created a
setup like shown below. But why does the error in view.ctp say:
"Notice (8): Undefined index: name"

Code:

models/sportsgroup.php
<?php
class SportsGroup extends Appmodel {
var $name = 'SportsGroup';
}
?>

controllers/sports_groups_controllers.php
<?php

class SportsGroupsController extends AppController {
var $helpers = array ('Html', 'Form', 'Js' => array('Jquery'),
'Javascript', 'GoogleMapView');
var $name = 'SportsGroups';

function index() {
$this->SportsGroup->recursive = 0;
$this->set('sportsgroups', $this->SportsGroup->find('all',
array('joins' => array(
array(
'table' => 'port_groups_entity',
'alias' => 'GroupsEntity',
'type' => 'inner',
'conditions'=> array('SportsGroup.group_id =
GroupsEntity.guid')
)
)
)));
$this->set('title_for_layout', 'Sportsclubs online');

}
function view($url = null) {
if (!$url) {
$this->Session->setFlash('Invalid id for Post.');
$this->redirect('/sportsclub/');
}
$this->set('post', $this->SportsGroup->findByUrl($url));
}
}

?>

view/sportsgroups/index.ctp (or view.ctp)
<?php foreach ($sportsgroups as $post): ?>
<?php echo $post['SportsGroup']['title']?> (it catches this one)
<?php echo $post['SportsGroup']['name']?> (but not this one)
<?php endforeach; ?>

view/sportsgroups/view.ctp
<?php echo $post['SportsGroup']['title']?> (it catches this one)
<?php echo $post['SportsGroup']['name']?> (but not this one)

The database table are like:
sports_groups: id | group_id | title
groups_entity: guid | name

Please help me, I used 2-3 days on this one..

/TheMuller

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate