【发布时间】:2021-12-18 00:13:22
【问题描述】:
我想在我的锚链接处于活动状态但无法正常工作时为其添加一个类。那么我该如何声明 $action 变量呢?
版本:
4.2.9
错误:
Undefined variable: action [ROOT\templates\layout\default.php, line 108]
模板/布局/default.php
<li>
<?= $this->Html->link(
'<div class="icon"></div>'.__('Summary'),
['controller' => 'modules', 'action' => 'summary'],
[
'escapeTitle' => false,
'class' => 'icon-summary '.( ($controller == 'Modules' && $action == 'summary') ? 'active' : '')
]
) ?>
</li>
在我的 ModulesController.php 中
public function summary()
{
$modules = $this->getAllModules();
}
来自 DebugKit 的路由参数
'controller' => 'Modules',
'action' => 'summary',
'pass' => [ ],
'plugin' => null,
'_matchedRoute' => '/{controller}/{action}/*',
'_ext' => null,
]
【问题讨论】:
-
这是因为这里没有定义名为
$action的变量。路由中有一个名为action的组件,但您还没有从那里提取它。 -
我必须在哪里提取它?在我的 ModulesController 中?
标签: php html model-view-controller cakephp