【问题标题】:Auth component in Cakephp 3.0Cakephp 3.0 中的 Auth 组件
【发布时间】:2015-04-17 08:55:48
【问题描述】:

我有一个免费安装的 Cakephp 3.0 实例和几个代码示例,一切正常。现在我想在./src/Auth 中创建一个Auth 组件,涉及文档here

这是我的代码:

<?php
namespace App\Auth; 
use Cake\Auth\BaseAuthenticate;
class AlephAuthenticate extends BaseAuthenticate
{
    public function authenticate(Request $request, Response $response)
    {
        // Do things for OpenID here.
        // Return an array of user if they could authenticate the user,
        // return false if not.
    }
}

在 AppContoller.php 我初始化这个组件:

public function initialize() {
        $this->loadComponent('Auth');
        $this->Auth->config('authenticate', ['Aleph']);
    }

在浏览器中调用应用程序URL显示:

致命错误:App\Auth\AlephAuthenticate::authenticate() 的声明必须与 /var 中的 Cake\Auth\BaseAuthenticate::authenticate(Cake\Network\Request $request, Cake\Network\Response $response) 兼容/www/art/src/Auth/AlephAuthenticate.php 第 7 行

知道这里有什么问题吗?

谢谢!

克里斯托夫

【问题讨论】:

    标签: php cakephp authentication


    【解决方案1】:

    请阅读很明显的错误信息。如果您仍然无法理解它just paste the error message into a search engine。这是几乎所有错误消息的基本过程,如果您不知道它并且可能总是解决它。猜猜它也在 php 文档中。

    让我为您重新表述错误消息:方法签名不匹配。为了摆脱错误信息,使它们匹配。

    【讨论】:

    • 谷歌搜索错误消息是我现在所做的。对我来说,问题是这里完全不匹配。方法authenticate在类BaseAuthorize.php中定义: abstract public function authorize($user, Request $request);
    • 在顶部添加命名空间:use Cake\Network\Request;和响应。因为只是 Request 在您的命名空间中是未知的。这将使其仅作为“请求”可用。 php.net/manual/en/language.namespaces.php
    猜你喜欢
    • 1970-01-01
    • 2011-09-09
    • 2011-07-31
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    • 2011-05-09
    • 1970-01-01
    • 2010-12-13
    相关资源
    最近更新 更多