Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    •  
      CommentAuthorbigtalk
     

    Hello,

    I've created the admin end of my site. I can create records via the back-end and look at them. Yay!
    So how do I access and display this great info on the front-side? For example, I would like to diplay just the Title and Body of a record in the table "news". I'm sure this is fairly simple, but the answer is eluding me.
    I'm using PageController for the front-end, NewsController extends AdminController, and I have a News model who's associated installer (news_installer) I used to create the news table in MySQL.
    I looked around the forum for this solution but was not able to locate it. My apologies if I missed it and am being redundant.

    -BigTalk

    •  
      CommentAuthorbigtalk
     

    I have been successful in getting a view of the Names of the columns in News, but it won't show any of the actual data in the fields.

    I am using:

      {?news}
      <div>
      <table cellspacing="0" summary="_{Listing available News}">
    
        <tr>
          <?php  $content_columns = array_keys($News->getContentColumns()); ?>
          {loop content_columns}
            <th scope="col"><?php echo $pagination_helper->sortable_link($content_column) ?></th>
          {end}
        </tr>
    
        {loop news}
        <tr {?news_odd_position}class="odd"{end}>
          {loop content_columns}
          <td class="field"><?php echo $News->get($content_column) ?></td>
          {end}
        </tr>
        {end}
      </table>
      </div>
      {end}  
    

    This has really gotten me stuck. Maybe someone in the Seattle area would like to trade; Akelos/PHP lessons of saxophone/music theory lessons?

    Thank you some more,
    BigTalk

    • CommentAuthorKaste
     

    hm,

    {loop news}
    

    inside the loop you would have to use the singular of 'news' which is ... 'news'.

    compiled code then should be

    foreach ($news as $key=>$news)...
    

    dont know a workaround right now.

    • CommentAuthorKaste
     

    I'd take the lessons, but Im not in Seattle %

    • CommentAuthorKaste
     

    brr.. you can always write

    {loop something as otherthing}
    

    in sintags. like in the foreach-statement

    •  
      CommentAuthorbigtalk
     

    On the admin side of my site,

    {loop news}   
    

    is working fine. I did change it on the front-side to

    {loop news as blog}
    

    just to see if it would have an effect, but it doesn't.
    Any other thoughts as to what I'm missing? Again, it is obviously connecting to the database and finding the table, because it lists the columns. Just doesn't fill them with data the way it does on my admin-side.

    Kaste - Thanks for writing me, I've been hoping for some help for weeks! You are Super-Hero!

    • CommentAuthorKaste
     

    so this

    <tr>
      <?php  $content_columns = array_keys($News->getContentColumns()); ?>
      {loop content_columns}
        <th scope="col"><?php echo $pagination_helper->sortable_link($content_column) ?></th>
      {end}
    </tr>
    

    works, and

    {loop news}
    <tr {?news_odd_position}class="odd"{end}>
      {loop content_columns}
      <td class="field"><?php echo $News->get($content_column) ?></td>
      {end}
    </tr>
    {end}
    

    doesn't work?

    then it seems because of

     $News->getContentColumns()
    

    doesn't throw, $News can't be an array but must be an active record. so you can't loop over $News.

    A standard scaffold has e.g. for 'book' two variables in the listing-view.

    • $book as in array_keys($Book->getContentColumns()
    • $books as in {loop books}

    Can you do

     $this->RecentNews = $this->News->find('all);
    

    in the controller and then {loop RecentNews} ...?

    •  
      CommentAuthorbigtalk
     

    I tried that and it still doesn't give me anything. Maybe I'll change News to Scoop. Then I can have Scoop and Scoops. Eliminate the pluralization problem altogether.

    Do I need anything in my controller to make accessing the data in MySQL work? As it stands, I only have:

     var $models = array('news', 'track');
    
     function index()
     {
       $this->RecentNews = $this->News->find('all');
     }
    

    in my controller. Any logic that doesn't already exist in Akelos?

    • CommentAuthorKaste
     

    Can you just output:

    $this->RecentNews = $this->News->find('all');
    foreach ($this->RecentNews as $item){
        echo $item->toString();
    }
    

    and look into log/development.log for the generated sql.

    Maybe we don't have any news?

    •  
      CommentAuthorbigtalk
     

    Thank you Kaste!

    Filling RecentNews with the News and then looping through RecentNews as $item does the trick. My application doesn't seem to be generating log/development.log for whatever reason. But I was able to display my data!
    Here's the code that works for me:

    In my controller:

         function index()
         {
           $this->RecentNews = $this->News->find('all');
         }  
    

    And in my view:

       {?news}
       <div>
          <table cellspacing="0" summary="_{Listing available News}">
            <tr>
            <?php  $content_columns = array_keys($News->getContentColumns()); ?>
               {loop content_columns}
               <th scope="col">
                 <?php echo $pagination_helper->sortable_link($content_column) ?>
               </th>
               {end}
            </tr>
            {loop RecentNews as item}
            <tr {?item_odd_position}class="odd"{end}>
               {loop content_columns}
               <td class="field">
                 <?php echo $item->get($content_column); ?>
               </td>
               {end}
            </tr>
            {end}
         </table>
      </div>
      {end}  
    

    This completely works.
    One more question. Is there an Akelos method that will let my display only the most recent data? All of my data has a "posted_at" column.

    • CommentAuthorKaste
     

    man, give me the ten most recent news is usually

    ->find('all',array('order'=>'posted_at desc','limit'=>10);
    
    •  
      CommentAuthorbigtalk
     

    That's it! Thank you!
    I just made it

     ,'limit'=>1);  
    

    Works just like I want it.

    Cheers Kaste!!!