Listed all options

This commit is contained in:
Kevin Frantz 2018-07-14 19:26:55 +02:00
parent 5c5eb64fd8
commit f938f70e78
3 changed files with 60 additions and 4 deletions

View File

@ -2,6 +2,7 @@
namespace controller\standart;
use controller\AbstractController;
use router\Link;
/**
*
@ -11,7 +12,32 @@ use controller\AbstractController;
final class Standart extends AbstractController implements StandartInterface
{
public function homepage():void{
$this->render('standart/homepage.html.twig');
$this->render('standart/homepage.html.twig',['options'=>$this->getAllOptions()]);
}
private function getAllOptions(){
return [
new Link([
'controller'=>'user',
'action'=>'login'
],'login'),
new Link([
'controller'=>'user',
'action'=>'logout'
],'logout'),
new Link([
'controller'=>'user',
'action'=>'register'
],'register'),
new Link([
'controller'=>'product',
'action'=>'list'
],'product list'),
new Link([
'controller'=>'order',
'action'=>'basket'
],'basket'),
];
}
}

View File

@ -6,7 +6,7 @@ namespace router;
* @author kevinfrantz
*
*/
class Url
class Link
{
/**
* ArrayCollection would be nicer but I have to save time ;)
@ -14,19 +14,39 @@ class Url
*/
private $parameters;
/**
*
* @var string
*/
private $name;
public function __construct(array $parameters=[],string $name = ''){
$this->setParameters($parameters);
$this->setName($name);
}
public function setParameters(array $parameters):void{
$this->parameters = $parameters;
}
public function setName(string $name):void{
$this->name = $name;
}
public function getName():string{
return $this->name;
}
public function getUrl():string{
return "index.php".$this->getParameters();
}
private function getParameters():string{
$parameters = '?';
foreach ($parameters as $key=>$value){
foreach ($this->parameters as $key=>$value){
$parameters .= $key.'='.$value.'&';
}
return $parameters;
}
}

View File

@ -1,3 +1,13 @@
{% extends "frames/default.html.twig" %}
{% block title %}Homepage{% endblock %}
{% block content %}Welcome to the online shop ;){% endblock %}
{% block content %}
<h2>Welcome to the online shop!</h2>
You have the following options:
<ul>
{% for option in options %}
<li>
<a href="{{option.getUrl}}">{{option.getName}}</a>
</li>
{% endfor %}
</ul>
{% endblock %}