允许对某些页面的权限cakephp [英] Allow permission to some page cakephp

查看:300
本文介绍了允许对某些页面的权限cakephp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在cakephp中创建我的网站的一些权限,但没有工作权限检查。
我只想例如只允许页添加其他页像 index register



这是我的AppController组件



<$> p $ p> public $ components = array(
'Session',
'Auth'=> array(
'loginAction'=> array '='''''''''''''''''''''''''''''''''&' ,'action'=>'index'),
'authError','b' =>'Questa risorsa non sembra appartenere al tuo account,oppure non hai eseguito l\'accesso',
'autoRedirect'=> false,
'authorize'=> array(
'Controller',
'Actions'=> array(
'actionPath'=>'controllers'

),
'authenticate' > array(
'Form'=> array(
'fields'=> array('username'=>'email')



);

这是UserController内的beforeFilter:

  public function beforeFilter(){
parent :: beforeFilter();
$ this-> Auth-> deny('*'); //我也试过$ this-> Auth-> deny();
$ this-> Auth-> allow('register');
}

为什么我可以访问其他页面?感谢

解决方案

来自Cakephp book:默认情况下,所有操作都需要授权。但是,在公开操作后,您想要撤销公共访问权限。你可以这样做使用AuthComponent :: deny():
你在做什么deny可能只是因为缺乏知识如何Auth工作。请检查此 http:// book。 cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html
$ this-> Auth-> deny(); //将删除所有操作。


I want to create some permission to my site in cakephp but not works permission check. I want only for example allow only the page add the other page like index or register doesn't have access.

This is my AppController component

public $components = array(
        'Session',
        'Auth' => array(
            'loginAction' => array('controller'=>'users','action'=>'login', 'admin'=>false),
            'logoutRedirect' => array('controller'=>'users','action'=>'logout'),
            'loginRedirect' => array('controller'=>'shows', 'action'=>'index'),
            'authError' => 'Questa risorsa non sembra appartenere al tuo account, oppure non hai eseguito l\'accesso',
            'autoRedirect' => false,
            'authorize' => array(
                'Controller',
                'Actions' => array(
                    'actionPath' => 'controllers'
                )
            ),
            'authenticate' => array(
                'Form' => array(
                    'fields' => array('username' => 'email')
                )
            )
        )
    );

And this is the beforeFilter inside UserController:

public function beforeFilter () {
   parent::beforeFilter();  
   $this->Auth->deny('*'); //I have also tried $this->Auth->deny();
   $this->Auth->allow('register');
}

Why I can access to the other pages? Thanks

解决方案

From Cakephp book: By default all actions require authorization. However, after making actions public, you want to revoke the public access. You can do so using AuthComponent::deny(): What you are doing with deny is probably only because of lack of knowledge how Auth works. Please check this http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html $this->Auth->deny(); // Will remove all the actions.

这篇关于允许对某些页面的权限cakephp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆