tasmaniski / laminas-current-route
用于读取当前路由信息的视图助手:控制器、动作、模块名称
3.0.2
2020-04-09 15:46 UTC
Requires
- php: >=5.6
- laminas/laminas-dependency-plugin: ^1.0
- laminas/laminas-mvc: 3.0.*
Requires (Dev)
- phpunit/phpunit: ^5.0
This package is auto-updated.
Last update: 2024-09-09 19:59:30 UTC
README
IMPORTANT NOTE: If you find this package useful, please click on a star button and let me know, so I will gladly continue with the updates.
Laminas MVC - 当前路由助手
用于在任何视图(.phtml)文件中读取 控制器、模块、动作和路由名称 的视图助手,包括layout.phtml
安装
在您的 composer.json 文件中添加
{ "require": { "tasmaniski/laminas-current-route": "^3.0" } }
运行后: composer update
您需要注册新的模块。在文件 config/application.config.php 中添加
'modules' => array(
'...',
'CurrentRoute'
),
使用
在您的视图文件(.html)中包括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
真实世界示例
<?php $css_class = $this->currentRoute()->matchModule('admin') ? 'selected' : ''; ?>
<a href="/admin" class="<?php echo $css_class;?>">
Admin link
</a>