在CakePHP中,我将在哪里放置一个对会话用户执行检查的方法?

在CakePHP中,我将在哪里放置一个对会话用户执行检查的方法?

问题描述:

Background: I have a method levelCheck() which compares the current user's level to a few parameters, and returns a true or false. I need to be able to access this method from any controller, and I would also like to put a call to it inside a helper for use on menus, etc.


Question: Due to Cake's flexibility, I can call almost anything from almost anywhere with Cake. Where is the correct place to put this? In a custom Session (extended)? In the AppController? A new component dealing with the current user? In the UserModel or User Controller?

The important piece here is how would I (or others) determine the correct location for such a thing in the future?

背景: strong>我有一个方法 levelCheck() code> 将当前用户的级别与几个参数进行比较,并返回true或false。 我需要能够从任何控制器访问此方法,并且我还想在帮助器内调用它以在菜单上使用等。 p>


问题: strong>由于Cake的灵活性,我几乎可以在任何地方用Cake调用任何东西。 放这个的正确位置在哪里? 在自定义会话(扩展)? 在AppController中? 处理当前用户的新组件? 在UserModel或用户控制器中? p>

这里的重要部分是我(或其他人)将来如何确定此类事物的正确位置? p> DIV>

Put this method in AppController

class AppController extends Controller 
{

  function levelCheck(){
    # whatever
  }

}

This is the correct place of this action. Because AppController is extended in all the controller so this method can called using current controller object that is $this->levelCheck().

On AppController

function beforeFilter() 
 {

      $this->custome_componnetst_name->levelCheck(parameters.....); 
      /*action*/

}