Skip to content

View Helper for reading Controller, Module, Action name in view.

License

Notifications You must be signed in to change notification settings

maatata/zend-current-route

 
 

Repository files navigation

Zend Framework Current Route Helper

View Helper for reading Controller, Module, Action and Route name in any view(.phtml) file including layout.phtml

New version is here! Current version support Zend Framework 3

Install

Add in you composer.json file:

{
    "require": {
        "tasmaniski/zend-current-route": "^2.0"
    }
}

After running: sudo composer update

You need to register new module. Add in file config/application.config.php:

'modules' => array(
    '...',
    'CurrentRoute'
),

Note: if you want to use it in ZF2 app, add in composer.json version ^1.0

Use

Use this view helper in your view files(.html) including layout.phtml

// get current route info
$this->currentRoute()->getController();               // return current controller name
$this->currentRoute()->getAction();                   // return current action name
$this->currentRoute()->getModule();                   // return current module name
$this->currentRoute()->getRoute();                    // return current route name

// or simply check with current info
$this->currentRoute()->matchController('index');      // match "index" with current controller name
$this->currentRoute()->matchAction('index');          // match "index" with current action name
$this->currentRoute()->matchModule('application');    // match "application" with current module name
$this->currentRoute()->matchRoute('home');            // match "home" with current route name

Real world example

<?php $css_class = $this->currentRoute()->matchModule('admin') ? 'selected' : ''; ?>
<a href="/admin" class="<?php echo $css_class;?>">
    Admin link
</a>

About

View Helper for reading Controller, Module, Action name in view.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%