2010-01-31 78 views
2

我想使用Security :: allowedControllers和Security :: allowedActions。所以我有一个控制器,它看起来或多或少像这样CakePHP:使用安全:: allowedControllers和安全:: allowedActions

class AppController extends Controller { 
    var $components = array('Security'); //other components 
    //other stuff 
} 

class BookController extends AppController { 
    function beforeFilter() { 
     parent::beforeFilter(); 
     $this->Security->allowedControllers = array('Users'); 
     $this->Security->allowedActions = array('view'); 
     $this->Security->RequireAuth = array('search', 'results'); 
    } 
    //other stuff 
} 

行动“搜索”显示了一个表单,然后调用“结果”来显示搜索结果。我故意试图破坏。

对于我所了解的$ this-> Security-> allowedControllers和$ this-> Security-> allowedActions,我应该只能从控制器'Users'的操作'视图'中获取POST数据。特别是行为“结果”应该将我重定向到一个黑洞,因为它从控制器“书籍”的操作“搜索”中获取POST数据。

但事实并非如此。我甚至可以制作交叉控制器请求,并且永远不会被黑匣子,所以我想我没有正确使用这个变量。什么是触发跨控制器请求控制的正确方法?

+0

您可能希望将“PHP”标签添加到这个问题,以吸引更多的观众(即使它是非常特殊的蛋糕)。 – 2010-01-31 17:55:33

+0

而且*完全*无关:)我只是点击进入您的主页,'Gasse'不能用德语中的'ß'缩写。以防万一。 – 2010-01-31 17:57:20

+0

谢谢德国小费,我会解决它! ;-) – Andrea 2010-01-31 18:09:52

回答

0

试试这个:

$this->Security->allowedFields = array('Model.fieldname', ...); 

您需要添加不在模型到allowedFields像我想在表格Model.search字段的字段。