CakePHP -锚类未更改(未定义变量$action)

nwlls2ji  于 2022-11-11  发布在  PHP
关注(0)|答案(1)|浏览(128)

我想添加一个类到我的锚链接,当它是活动的,但它不工作。我将不得不声明$操作变量呢?
版本号:

4.2.9

错误:

Undefined variable: action [ROOT\templates\layout\default.php, line 108]

templates/layout/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>

在我的模板中

public function summary()
  {
      $modules = $this->getAllModules();
  }

DebugKit中的路由参数

'controller' => 'Modules',
'action' => 'summary',
'pass' => [ ],
'plugin' => null,
'_matchedRoute' => '/{controller}/{action}/*',
'_ext' => null,
]
zf9nrax1

zf9nrax11#

在我的AppController.php中,我在beforeRender()函数中插入了下面的代码。现在我可以访问action变量了。

$this->set('action', $this->request->getParam('action'));

非常感谢

相关问题