Advertisement
Guest User

Untitled

a guest
Jul 29th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AdminModule;
  4.  
  5.  
  6. /**
  7.  * Homepage presenter.
  8.  */
  9. class HomepagePresenter extends BasePresenter
  10. {    
  11.    
  12.      /**
  13.      * @var \App\Components\IArticleMenuFactory
  14.      * @inject
  15.      */
  16.    
  17.     public $articleMenuFactory;
  18.    
  19.     /** @persistent */
  20.     public $category;    
  21.     /**
  22.      *
  23.      * @return ArticleMenu
  24.      */
  25.     public function createComponentArticleMenu()
  26.     {
  27.  
  28.     $control = $this->articleMenuFactory->create();
  29.     $control['articleMenu']->onSuccess[] = function($form) {
  30.           $this->redirect('this', array('category' => $form->values->category));
  31.        
  32.     };
  33.         return $control;
  34.  
  35.     }  
  36.    
  37.     public function renderDefault() {
  38.          if($this->category) {
  39.               $this->template->articles = $this->articles->getArticleByCategoryId($this->category);      
  40.          } else {
  41.               $this->template->articles = $this->articles->fetchAll();
  42.          
  43.          }
  44.      
  45.      
  46.     }
  47.    
  48.     }
  49.    
  50.  
  51.    
  52. Šablona:
  53.  
  54. {block content}
  55. <br /> <br />
  56. <div class="main"><h3>Posledních 10 příspěvků:</h3> <br />
  57.  {control articleMenu}
  58.  
  59.  <br /> <br />
  60.  <table class="table-article-create">
  61.     <thead>
  62.         <tr>
  63.             <th>ID</th>
  64.             <th>Název</th>
  65.             <th>Text</th>
  66.             <th>Autor</th>
  67.             <th>Datum</th>
  68.             <th>Kategorie</th>
  69.         </tr>
  70.     </thead>
  71.     <tbody>
  72.         <tr n:foreach = "$articles as $article">
  73.    
  74.     <td>{$article->id}</td>
  75.     <td>{$article->title|striptags}</td>
  76.     <td class="content"><a n:href='Articles:edit $article->id'>{!$article->content|substr:0,35|striptags}</a></td>
  77.     <td>{$article->author ? $article->author:('Neznámý')}</td>
  78.     <td>{$article->datetime|date:"d.m.y H:i"}</td>
  79.     <td>{($category = $article->ref('categories','categories_id')) ? $category->name:('Nezařazeno')}</td>
  80.    
  81.  </tr>
  82. </tbody>
  83.  </table>
  84.  
  85. </div>
  86.  
  87. {/block}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement