Zend Literal Route

What is a Literal Route?

A Literal route matches exact URLs exactly as defined — no variables, no wildcards.

✅ Use Case:

You want to match a fixed path like /about, /contact, /login, etc.


Example Code

Route Configuration (module/Application/config/module.config.php)

Add this inside

use Application\Controller\MainController;

'router' => [
  'routes' => [
    'about' => [
      'type'  => \Laminas\Router\Http\Literal::class,
      'options' => [
        'route'  => '/about',
        'defaults' => [
          'controller' => MainController::class,
          'action'   => 'about',
        ],
      ],
    ],
  ],
],

Controller (MainController) (module\Application\src\Controller\MainController.php)

namespace Application\Controller;

use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;

class MainController extends AbstractActionController
{
  public function aboutAction()
  {
    return new ViewModel();
  }
}

View File (module/Application/view/application/main/about.phtml)

<h2>About Page</h2>
<p>This is the static About page.</p>

Access in Browser


http://localhost:8080/about

Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.