Re: Accessing variables in referenced tables in views

2010-09-14 Thread Andrew Alexander
So am I approaching this the wrong way?
I could make a method in my controller to retrieve the variables, but
that seems like bad design to me

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Accessing variables in referenced tables in views

2010-08-18 Thread Andrew Alexander
And yes thread.php and post.php has a belongsTo User.

post.php:
var $belongsTo = array(
'Thread' => array(
'className' => 'Thread',
'foreignKey' => 'thread_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Accessing variables in referenced tables in views

2010-08-18 Thread Andrew Alexander
Placing "" in view.ctp gives me the error:
Notice (8): Undefined variable: threads [APP\views\threads\view.ctp,
line 1]

If I use the "$thread" variable instead, I get an array with posts and
their user_ids but not the usernames:
"Array ( [Thread] => Array ( [id] => 7 [subject] => c [user_id] => 5
[body] => c [created] => 2010-08-16 14:00:31 [modified] => 2010-08-16
14:00:31 ) [User] => Array ( [id] => 5 [username] => root [password]
=> 6abfa9223de79de9fbb2327c8c999043c2210177 [group_id] => 1 [created]
=> 2010-08-16 12:20:32 [modified] => 2010-08-16 12:20:32 ) [Post] =>
Array ( [0] => Array ( [id] => 62 [subject] => [body] => ... [created]
=> 2010-08-17 14:43:42 [modified] => 2010-08-17 14:43:42 [thread_id]
=> 7 [user_id] => 8 ) [1] => Array ( [id] => 61 [subject] => [body]
=> ... [created] => 2010-08-17 14:43:38 [modified] => 2010-08-17
14:43:38 [thread_id] => 7 [user_id] => 8 ) [2] => Array ( [id] => 60
[subject] => . [body] => . [created] => 2010-08-17 14:43:34 [modified]
=> 2010-08-17 14:43:34 [thread_id] => 7 [user_id] => 8 ) ) ) "

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Accessing variables in referenced tables in views

2010-08-17 Thread Andrew Alexander
I am attempting to create a forum in php. In my project I have tables:
threads, posts, users. And each post has a foreign key for a thread
and a user. In my thread view I want to replace the user_id field with
the corresponding username for each post. I've tried "echo
$post['User']['username'];" but that gives me an error.

Is there a way to access the username variable from the thread view?


Here's the code I have in view now:

>





Html->link(__('View', true), 
array('controller'
=> 'posts', 'action' => 'view', $post['id'])); ?>
Html->link(__('Edit', true), 
array('controller'
=> 'posts', 'action' => 'edit', $post['id'])); ?>
Html->link(__('Delete', true),
array('controller' => 'posts', 'action' => 'delete', $post['id']),
null, sprintf(__('Are you sure you want to delete # %s?', true),
$post['id'])); ?>




Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en