Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorandrewl
     
    I'm in the process of learning how to get a list of books by an author in the booklink tutorial.

    I'm at the point where I'm adding a finder for books into the author 'show' action in the author controller.

    I have it working, courtesy of an example in another forum post. The line I added to the controller was:

    $this->authors = $this->Author->find(@$this->params['id'], array('include' => 'books'));

    But, I'm confused (and curious) about why we are assigning to $this->authors (plural) whereas in the book controller,
    when we added the finder for authors, we added the line:

    $this->book = $this->Book->find(@$this->params['id'], array('include' => array('main_author', 'co_author')));

    where $this->book is singular.

    Moreover, in the show view, both references are (as i would expect) singular...

    link_to($text_helper->translate('Edit this Book'), array('action' => 'edit', 'id'=>$book->getId()))
    link_to($text_helper->translate('Edit this Author'), array('action' => 'edit', 'id'=>$author->getId()))

    Can someone please explain this for me?

    many thanks,
    • CommentAuthorinsanet
     

    the thing is you can assign the result of a find to whatever you want, but for example in listing they assigned it to some plural variable because in the view there is this:

     {loop authors}
    

    and that do this:

     foreach($authors as $author)
    

    so when you use the sintax of "loop", the framework singularize the given word. and then is accessed (in singular of course) like {author.name} or $author->something. but in the show is only one object so there is no loop, and consenquently innecessary to use a plurar.

    so finally i would say that you only use plurals because you want it to work with "loop".

    • CommentAuthorandrewl
     
    Hi Insanet,

    Many thanks for your reply, that explains it perfectly.

    Btw, how do you get the yellow highlighted code into your comments? I can't seem to find any instructions for the forum on how to do that .
    • CommentAuthorinsanet
     
    first i press "markdown" button in the form, then whatever you type that starts with 4 spaces and is in a newline, is formatted. you also need a empty line above the line your writing but this is only need once for each block. you can practice with the preview post also.
    • CommentAuthorandrewl
     

    Thank you Insanet, much appreciated