0

我在 CakePHP 中扩展了 BaseAuthorise 并创建了一个名为 LdapAuthenticate 的新类,它位于我的 /app/Controller/Component/Auth/LdapAuthenticate 中,目前看起来像这样

<?php

App::uses('BaseAuthorize', 'Controller/Component/Auth');

class LdapAuthenticate extends BaseAuthorize {
    public function authenticate(CakeRequest $request, CakeResponse $response) {
        // Do things for ldap here.

        echo "Running...";

    }
}

在我的 AppControl 中,我有

public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home'),
            'authenticate' => array('Ldap')
        )
    );

然后在我的登录方法中,我有

public function login() {
    if ($this->request->is('post')) {

        $this->Auth->authorize();

    }
}

但是我收到了错误

Error: Class LdapAuthenticate contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (BaseAuthorize::authorize)  

然而,在 CakePHP 文档和食谱中,它指示我设置它的方式,我让 LdapAuthetnticate 扩展 BaseAuthorise 并使用一个用于身份验证的函数,根据用户是否登录,它可以返回一个 false 对象。

任何人都可以提出为什么会产生这个错误吗?

4

2 回答 2

0

正如 ndm 所说,您正在扩展,BaseAuthorize但您想要的是BaseAuthenticate

class LdapAuthenticate extends BaseAuthenticate
{

    public function authenticate(CakeRequest $request, CakeResponse $response)
    {
        // ....
        return $userData;
    }
于 2013-10-24T05:58:05.080 回答
0

你扩展了一个抽象类——所以你必须提供你自己的抽象方法的实现——在这种情况下你必须实现:

authorize ( array $user , CakeRequest $request )
于 2013-10-23T21:15:46.863 回答