0

Im just moving over to cakePHP from Code Igniter and I bet its right in front of me, but i can for the love of god not figure out through the manual nor search the internet, how to access relationship data. For example, say I have two tables BOOKS and AUTHORS. When accessing /books/ and getting a list printed, i can have perhaps ID and Title printed, and author_id. But How do I actually print out the authors first and last name? its in the AUTHORS table?

This, in Code Igniter (using dmz) I simply wrote $book->author->first_name I just cant seem to find/figure out how its done in cakephp.

(Yes i have the relationship set up in the models)

very grateful for anyone to tell me how, or just point me to where to learn it. Not lazy, been looking, just cant find it.

regards, Jason

1
  • 4
    Try debug($books) on the retrieved data. If your relationships are set up correctly, the author should be in there. Commented Nov 25, 2010 at 23:30

2 Answers 2

1

If your relationships are setup correctly, you can

echo $data['Book']['Author']['firstname'];

This should allow you to ouput the stuff.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you, i found out it was just the syntax that differed between the way its done in CI compared to cakePHP.
0

If the 'Author' data isn't in $books you should make sure your recursion is set properly:

$this->Book->recursive = 1;

Or that you have the 'Author' model contained:

$this->Book->find('all', array('contain' => array('Author'));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.