thank you for your patience but here is the deal:
i have module directory set to Application as default module and Blog.
As the documentation said I put my ‘navigation’ container code in the Application->config->module.config.php and the default code is:
'navigation' => [
'default' => [
[
'label' => 'Home',
'route' => 'home',
],
[
'label' => 'Blog',
'route' => 'blog',
'pages' => [
[
'label' => 'All',
'route' => 'blog',
'action' => 'index',
],
[
'route' => 'blog/detail',
'action' => 'detail',
],
[
'route'=>'blog/category',
'action'=>'category',
],
],
],
],
in my Blog module the config file under Blog->config->module.config.php the route is like this:
'router' => [
// Open configuration for all possible routes
'routes' => [
// Define a new route called "blog"
'blog' => [
// Define a "literal" route type:
'type' => Literal::class,
// Configure the route itself
'options' => [
// Listen to "/blog" as uri:
'route' => '/blog',
// Define default controller and action to be called when
// this route is matched
'defaults' => [
'controller' => Controller\ListController::class,
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes'=> [
'detail'=>[
'type'=>segment::class,
'options'=>[
'route'=>'/single/:id',
'defaults'=>[
'action'=>'detail',
],
'constraints'=>[
'id'=>'[1-9]\d*',
],
],
],
'category'=>[
'type'=>segment::class,
'options'=>[
'route'=>'/subpage-category/id-:cid/:title',
'defaults'=>[
'action'=>'category',
],
'constraints'=>[
//'catTitle'=>'[a-zA-Z][a-zA-Z0-9_-]*',
'cid'=>'[1-9]\d*',
],
],
],
],
],
],
],
I have put the code you recommended in Application config like this:
use Zend\Navigation\Navigation;
$navigation = new Navigation(
[
'default'=>[
[
'label'=>'Home',
'route'=>'home',
],
[
'label'=>'Blog',
'route'=>'blog',
'pages'=> [
'label'=>'category',
'route'=>'blog/category',
'pages'=>[
'label'=>'Detail',
'route'=>'blog/detail',
],
]
]
]
]);
return [
'router' => [
'routes' => [
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'application' => [
'type' => Segment::class,
'options' => [
'route' => '/application[/:action]',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
],
],
'controllers' => [
'factories' => [
Controller\IndexController::class => InvokableFactory::class,
],
],
'view_manager' => [
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => [
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
],
'template_path_stack' => [
__DIR__ . '/../view',
],
],
/*'navigation' => [
'default' => [
[
'label' => 'Home',
'route' => 'home',
],
[
'label' => 'Blog',
'route' => 'blog',
'pages' => [
[
'label' => 'All',
'route' => 'blog',
'action' => 'index',
],
[
'route' => 'blog/detail',
'action' => 'detail',
],
[
'route'=>'blog/category',
'action'=>'category',
],
],
],
],
],*/
$navigation
];
and used the $page in the detail page here:
$page = $this->navigation('default')->findOneBy('route', 'blog/detail');
$page->setParams(['id' => $post->getId()]);
$page->setLabel($post->getTitle());
but it does not work where am i wrong?