2012-08-23 05:57
浏览 45

CakePHP 2.2.1(稳定版)中$ this-> auth-> authorize(cakephp 1.3)的变化是什么?

I am upgrading an app from CakePHP 1.3 to CakePHP 2.2.1 .

We are implementing ACL and in AppController I saw

if (isset($this->Auth)) {
            if ($this->use_acl) {
                $this->Auth->authorize = 'actions';

As a variable declaration I have already made changes to the following :

var $components = array(
        'Auth' => array(
            'authenticate' => array(
                'Form' => array(
                'fields' => array('username' => 'email', 'password' => 'password')
            'loginAction' => array(
                'admin' => false, 'prefix' => false, 'controller' => 'users', 
                'action' => 'login')
        'Session', 'Facebook.Connect');

does it still require me to keep:

$this->Auth->loginAction = array('admin' => false, 'prefix' => false, 'controller' => 'users', 'action' => 'login');

The code work may sound ugly but, that is how upgrades are! ;)

Also, can I use the $this->Auth-> 'auth properties' in 2.2.1 as it was possible in 1.3 ?

图片转代码服务由CSDN问答提供 功能建议

我正在将应用程序从CakePHP 1.3升级到CakePHP 2.2.1。


  if(isset($ this-> Auth)){
 if($ this-> use_acl){\  n $ this-> Auth-> authorize ='actions'; 

作为变量声明我已经对以下内容进行了更改:< / p>

  var $ components = array(
'Auth'=&gt; array(
'authenticate'=&gt; array(
'Form'=&gt; array(\  n'fields'=&gt; array('username'=&gt;'email','password'=&gt;'password')
'loginAction'=&gt; array(
'admin  '=&gt; false,'前缀'=&gt; false,'controller'=&gt;'用户',
'会话','Facebook.Connect  '); 


  $ th  is-&gt; Auth-&gt; loginAction = array('admin'=&gt;  false,'prefix'=&gt;  false,'controller'=&gt;  'users','action'=&gt;  'login'); 

代码工作可能听起来很难看,但这就是升级的方式! ;)

另外,我可以使用$ this-&gt; Auth-&gt; 2.2.1中的“auth properties”,因为它可能在1.3?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxiong4250 2012-08-23 06:23

    As usual, the best place to get started with questions like this is the manual. Then, post the results of your tests rather than your code and a broad question.

    That said, the first block of code you posted looks like a custom variable on your end $this->use_acl. I've never seen that used in CakePHP, so there's some flag your setting in your app to use 'actions'.

    The second block of code looks pretty standard. It should work. Yes, you still need to specify a login action so that when a user tries to navigate to a page that is protected, then he/she will be redirected to the login. That said, there are differences in the login process as noted in the manual link above. You should take a look at the differences as to when a password is hashed and the login() function itself as they both have changed. The fact you are using ACL shouldn't matter much as far as Authentication differences between the two version.

    Your last question Also, can I use the $this->Auth-> 'auth properties' in 2.2.1 as it was possible in 1.3 ?, the answer is yes. You should take a look at the AuthComponent.php file in the lib/Cake folder. It's heavily commented about the information you are asking about here. There are even examples.

    打赏 评论

相关推荐 更多相似问题