1. Go to this page and download the library: Download mimmi20/mezzio-navigation library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Laminas\Config\Config;
use Mimmi20\Mezzio\Navigation\Navigation;
use Mimmi20\Mezzio\Navigation\Page\PageFactory;
// create container
$container = new Navigation();
// add page by giving a page instance
$container->addPage(new Class implements PageInterface{});
// add page by giving a page instance using the PageFactory
$container->addPage((new PageFactory())->factory([
'uri' => 'http://www.example.com/',
]));
$pages = [
new Class implements PageInterface{},
new Class implements PageInterface{},
];
// add two pages
$container->addPages($pages);
// remove existing pages and add the given pages
$container->setPages($pages);
> $page = new Mimmi20\Mezzio\Navigation\Page\Route();
> $page->foo = 'bar';
> $page->meaning = 42;
>
> echo $page->foo;
>
> if ($page->meaning != 42) {
> // action should be taken
> }
>
use Mimmi20\Mezzio\Navigation\Page;
/**
* Dispatched request:
* - route: index
*/
$page1 = new Page\Route([
'route' => 'index',
]);
$page2 = new Page\Route([
'route' => 'edit',
]);
$page1->isActive(); // returns true
$page2->isActive(); // returns false
/**
* Dispatched request:
* - route: edit
* - id: 1337
*/
$page = new Page\Route([
'route' => 'edit',
'params' => ['id' => 1337],
]);
// returns true, because request has the same route
$page->isActive();
/**
* Dispatched request:
* - route: edit
*/
$page = new Page\Route([
'route' => 'edit',
'params' => ['id' => null],
]);
// returns false, because page
namespace My;
use Mimmi20\Mezzio\Navigation\Page\PageInterface;
use Mimmi20\Mezzio\Navigation\Page\PageTrait;
class Page implements PageInterface
{
use PageTrait;
public function getHref(): string
{
return 'something-completely-different';
}
}
namespace My\Navigation;
use Mimmi20\Mezzio\Navigation\Page\PageInterface;
class Page implements PageInterface
{
protected $foo;
protected $fooBar;
public function setFoo($foo)
{
$this->foo = $foo;
}
public function getFoo()
{
return $this->foo;
}
public function setFooBar($fooBar)
{
$this->fooBar = $fooBar;
}
public function getFooBar()
{
return $this->fooBar;
}
public function getHref(): string
{
return sprintf('%s/%s', $this->foo, $this->fooBar);
}
}
// Instantiation:
$page = new Page([
'label' => 'Property names are mapped to setters',
'foo' => 'bar',
'foo_bar' => 'baz',
]);
use Mimmi20\Mezzio\Navigation\Page\PageInterface;
// Route page, as "route" is defined
$page = (new PageFactory())->factory([
'label' => 'Home',
'route' => 'home',
]);
// Route page, as "type" is "route"
$page = (new PageFactory())->factory([
'type' => 'route',
'label' => 'My Route page',
]);
use Mimmi20\Mezzio\Navigation\Page\PageInterface;
// URI page, as "uri" is present, with now MVC options
$page = (new PageFactory())->factory([
'label' => 'My URI page',
'uri' => 'http://www.example.com/',
]);
// URI page, as "uri" is present
$page = (new PageFactory())->factory([
'label' => 'Search',
'uri' => 'http://www.example.com/search',
'active' => true,
]);
// URI page, as "uri" is present
$page = (new PageFactory())->factory([
'label' => 'My URI page',
'uri' => '#',
]);
// URI page, as "type" is "uri"
$page = (new PageFactory())->factory([
'type' => 'uri',
'label' => 'My URI page',
]);
namespace My\Navigation;
use Mimmi20\Mezzio\Navigation\Page\PageInterface;
class Page extends PageInterface
{
protected $fooBar = 'ok';
public function setFooBar($fooBar)
{
$this->fooBar = $fooBar;
}
}
// Creates Page instance, as "type" refers to its class.
$page = (new PageFactory())->factory([
'type' => Page::class,
'label' => 'My custom page',
'foo_bar' => 'foo bar',
]);
return [
'modules' => [
'Mezzio\Router',
'Mezzio\Navigation', // <-- Add this line
// ...
],
];
return [
'middleware' => [
'Mezzio\Authentication\AuthenticationMiddleware', // <-- not
$app->pipe(\Mimmi20\Mezzio\Navigation\NavigationMiddleware::class);
// Register the routing middleware in the middleware pipeline.
// This middleware registers the Mezzio\Router\RouteResult request attribute.
$app->pipe(RouteMiddleware::class);