Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Components;
- use Nette\Application\UI\Form;
- class ArticleMenu extends \Nette\Application\UI\Control {
- /** @var Articles */
- private $articles;
- /** @var string */
- public $categoryID;
- /**
- * @param Articles $articles
- * @param string $categoryID
- */
- public function __construct($categoryID, \App\Model\Articles $articles) {
- parent::__construct();
- $this->articles = $articles;
- $this->categoryID = $categoryID;
- }
- protected function createComponentArticleMenu() {
- $form = new Form();
- $form->addSelect('category','Kategorie', $this->articles->getArticleCategories()->fetchPairs('id', 'name'))
- ->setPrompt('VΕ‘echny ΔlΓ‘nky');
- $form->addSubmit('submit', 'Zobrazit');
- return $form;
- }
- public function articleMenuSuceeded($form, $categoryID) {
- $this->articles = !empty($categoryID) ?
- $this->articles->getByCategoryId($categoryID) :
- $this->articles->fetchAll();
- $form->onSuccess[] = $this->articleMenuSuceeded;
- $this->redirect('this', ['categoryID' => $form->values->category]);
- }
- public function render() {
- $this['articleMenu']->render();
- }
- }
- interface IArticleMenuFactory {
- /**
- * @param string $categoryID
- * @return ArticleMenu
- */
- function create($categoryID);
- }
- <?php
- namespace App\Model;
- /**
- * Description of Articles
- *
- * @author Freestyler
- */
- class Articles extends Base {
- /*
- * Get all articles from db (limited to 10)
- */
- public function fetchAll() {
- return $this->database->table('articles')
- ->limit('10');
- }
- /**
- * Add article to db
- */
- public function addArticle() {
- }
- /**
- *
- * Get all categories
- */
- public function getArticleCategories() {
- return $this->database->table('categories');
- }
- /*
- * Get specific article based on category_id
- */
- public function getArticleByCategoryId($categoryID) {
- return $this->database->table('articles')
- ->where('categories_id', $categoryID);
- }
- }
- config.neon
- #
- # SECURITY WARNING: it is CRITICAL that this file & directory are NOT accessible directly via a web browser!
- #
- # If you don't protect this directory from direct web access, anybody will be able to see your passwords.
- # http://nette.org/security-warning
- #
- parameters:
- php:
- date.timezone: Europe/Prague
- # zlib.output_compression: yes
- nette:
- application:
- errorPresenter: Error
- mapping:
- session:
- expiration: 14 days
- services:
- authenticator: App\Model\Authenticate
- - App\RouterFactory
- - App\Model\Articles
- -
- implement: IArticleMenuFactory
- parameters: [categoryID]
- arguments: [%categoryID%]
- router: @App\RouterFactory::createRouter
- <?php
- namespace AdminModule;
- /**
- * Homepage presenter.
- */
- class HomepagePresenter extends BasePresenter
- {
- /**
- * @var App\Components\IArticleMenuFactory
- * @inject
- */
- public $articleMenuFactory;
- protected function createComponentArticleMenu()
- {
- return $this->articleMenuFactory->create();
- }
- /**
- * Fetch all articles to table
- */
- public function beforeRender() {
- $this->template->articles = $this->articles->fetchAll();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment