如何在cakephp 3中使用别名助手?

时间:2015-03-30 10:55:31

标签: helper cakephp-3.0

我需要修改Html->链接以在生成链接之前检查acl。然后我使用别名助手来做到这一点。我有appController

public $helpers = ['Tools' , 'Html' => ['className' => 'Mhtml']];

在src / View / Helper / MhtmlHelper.php我有

<?php
namespace App\View\Helper;
use Cake\View\Helper;
use Cake\View\Helper\HtmlHelper;

class MhtmlHelper extends HtmlHelper {

    public function acl() {
        //return true if it is able to verify the user’s access, else false
    }

    public function link($title , $url=null , $options=[]) {
        return $this->acl ? parent::link($title , $url , $options) : '';
    }

}

但是我遇到了这个错误

Strict (2048): Declaration of App\View\Helper\MhtmlHelper::link() should be compatible with Cake\View\Helper\HtmlHelper::link($title, $url = NULL, array $options = Array) [APP/View\Helper\MhtmlHelper.php, line 6]

有什么问题?

1 个答案:

答案 0 :(得分:1)

您需要声明link函数,如下所示:

public function link($title , $url = null , array $options = []) {
    return $this->acl ? parent::link($title , $url , $options) : '';
}