1

我在 CakePHP 1.3 中使用 ACL 没有任何问题,经过 2 周的痛苦挫折后,它仍然无法在 CakePHP 2.0 中工作。

我完全按照 Cake ACL 教程进行操作,但没有任何反应。所有 Aros 都正确,ACOS 和权限相同。

毕竟,我可以毫无问题地输入所有被拒绝的操作。

特此我的AppController:

public $components = array('Acl','Auth'=> array(
                            'authenticate' => array(
                                'Actions',
                                'Form' => array(
                                    'fields' => array('username' => 'email')
                                    ),
                            )
), 'Session', 'MathCaptcha', 'RequestHandler');

在我的前置过滤器中:

    $this->Auth->actionPath = 'controllers';
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
    $this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'home');
    $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'profile');
    $this->Auth->allow('display');

有人知道出了什么问题。谢谢!

4

2 回答 2

2

Auth 组件从 CakePHP 1.3 到 2.0 发生了很大变化。在将应用程序从 1.3 迁移到 2.0 时,我遇到了类似的问题。我发现设置授权选项是我需要进行更改的地方:

在前置过滤器中:

$this->Auth->authorize = array(
    'Actions' => array(
        'userModel' => 'User',
        'actionPath' => 'users'
    )
);

userModel 是 Aro 表中使用的模型类。actionPath 是 Acl 在 Aco 表中检查的操作的根级别。

您可能还想拒绝然后允许:

$this->Auth->deny('*');
$this->Auth->allow('display');

希望这可以帮助。

于 2011-11-09T02:21:41.110 回答
2

在 CakePHP 2.0 中,我这样做了:

应用程序/控制器/AppController.php

class AppController extends Controller {

    public $components = array(
        // others components...
        'Session',
        'Acl',
        'Auth'=> array(
            // Setting AUTHORIZATION "What can you do?"
            'authorize' => array(
                'Actions' => array(
                    'actionPath' => 'controllers'
                 )
            ),

            // Setting AUTHENTICATION "Who are you?"
            'authenticate' => array(
                'Form' => array(
                    'fields' => array(
                        'username' => 'email', 'password' => 'password'
                    )
                )
            )
        )
    );

// other stuffs...

使用这种方法,ACL 将使所有肮脏的工作。正如您可能知道的那样,没有必要检查许可证。

我相信你对 ARO 和 ACO 没意见,没什么大不了的。以防万一: http ://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application.html#simple-acl-controlled-application

CakeBook for 2.0 显示了一个名为 AclExtras 的控制台插件,用于构建您的 ACO。您的 ARO 将随着用户和组的添加/删除而构建。我已经使用这个插件来生成关于我已经填写的表格的 ARO:http ://www.alaxos.ch/blaxos/pages/view/plugin_acl 。这适用于 fos 1.3,但有一个适用于 2.0 的测试版可以正常工作。

之后,您必须设置许可。手动(或从控制台)此链接描述:http ://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/part-two.html#setting-up-permissions . 或者使用 Alaxos 的插件在视觉上。

我希望这有帮助!它对我有用。我正在使用 CakePHP 2.0.2

于 2011-11-18T02:24:13.373 回答