Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthormstram
     
    Greetings,
    I've just installed ver 0.7.1 of Akelos on both my Win XP Xampp box and and a hosted Linux box.
    I've created the booklink application, and it generally is working.

    I'm trying to figure out the syntax ... or maybe it's a bug... on how to find the "children", in this case all the books by an author.

    I watched the blog screencast and I tried to copy the code that listed the comments modified to :
    {loop author.books}
    <p> book.id {book.id}
    <p> book.title {book.title}
    {end}
    (and put that in author/show.tpl)

    ..but I'm getting nothing printed for the books.
    http://mstram.webfactional.com/bl/?ak=/author/show/1/

    (There ARE entries in the database for
    the books table with the correct author_id values (as displayed on this page :
    http://mstram.webfactional.com/bl/?ak=/book/listing/

    When I run the script/console, I tried the following commands :

    $a = new Author
    $author1 = $a->find(1)
    $booklist = $author1->books
    print_r($booklist)

    .. and I get an empty Array object for '$booklist'

    (btw how do you exit the console? I tried ctr-d, ctr-z .. 'quit')

    Mike
    •  
      CommentAuthorbermi
     

    Hi Mike,

    Welcome to the Akelos forums!

    Associated records need to be loaded implicitly in Akelos, so in your previous console example you'll need to do something like

    $a = new Author(1);
    $booklist = $a->book->load();
    Ak::debug($booklist);
    

    Including associations can be done easily by adding the include option in the finder like in this controller example

    function listing(){
        $this->Authors = $this->Author->find('all', array('include' => 'books'));
    }
    

    and then this Sintags in the view

    {loop Authors.books}
        <p>book.id {book.id}</p>
        <p>book.title {book.title}</p>
    {end}
    

    And regarding you last question, to close Akelos console you just need to type

    exit
    

    I hope you find it useful :D

    • CommentAuthormstram
     
    1) I have it working now !

    I went back and looked at your blog example again and saw the code you were using in the 'show' function.

    I added this code to the authors/show function :

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

    2) ----------
    In the console when I enter :

    $booklist = $a->book->load();

    I'm getting an error :
    "Function load() doesn't exist"

    Mike

    p.s. how do you format your "code" in this forum? (I tried [code] and <code> ... neither work).
    • CommentAuthormstram
     
    Ok, as I wrote in my previous post, the "children" (books) for each author ARE now displayed when "drilling" down to the detail (show) page for an author.

    Now I'm trying to figure out the syntax to use when displaying the parents/children on the same page .. i.e. the "listing" view.

    In Rails, I can do it with this code in the view :

    <% for author in @authors %>
    <%= link_to author.name, :controller => 'authors', :action => 'show', :id => author.id %>

    <% books = author.books %>

    <% for book in books%>
    <%= link_to book.title, :controller => 'books', :action => 'show', :id => book.id %></td></tr>
    <% end %>
    <% end %>

    So in Akelos I tried the code below, but am getting an error with the compiled code.

    {loop authors}
    <%= link_to author.name, :action => 'show', :id => author.id %>
    {books = author.books }
    {loop books }
    <%= link_to book.title, :controller => 'books', :action => 'show', :id => book.id %>
    {end}
    {end}


    e.g. :
    Author1
    Book1
    Book2
    Book3

    Author2
    Book4
    Book5
    •  
      CommentAuthorbermi
     

    Mike,

    Assigning variables like this

    {books = author.books}
    

    is not implemented yet in Sintags. You could have used plain PHP for that like

    <? $books = $author->books ?>
    

    but it is not necessary to assign that var as SIntags loops can take author.books as a parameter like this

    {loop authors}
        <%= link_to author.name, :action => 'show', :id => author.id %>
        {loop author.books}
            <%= link_to book.title, :controller => 'books', :action => 'show', :id => book.id %>
        {end}
    {end}
    

    Regarding, formatting on the forum, you can select Format comments as Markdown and indent code with 4 spaces.

    • CommentAuthormstram
     

    I'm not getting any books displayed.

    '$author->books' 
    

    is apparently not finding any of the books

    I changed : empty($author->books) ? null : $books_available = count($author->books); to empty($author->books) ? $books_available = 0 : $books_available = count($author->books); echo "

    <

    p> books_available = ",$books_available;

    and am getting " books_available = 0"

    I also tried : $booksload = $author->books->load(); echo "

    <

    p> $booksload = ",$booksload;

    and am getting Fatal error: Call to a member function load() on a non-object in D:\xampplite\htdocs\akelos\app\views\author\compiled\listing1.tpl.php on line 64

    which looks to me to be related to the other message I posted about getting an error message for the error I was getting in the console for the :

    $booklist = $a->book->load();
    

    statement.

    Mike