我有带有前缀的db表,并且需要在app_controller中可读取beforeFilter
$prefix_array = array('admin', 'marketing');
if ($this->Auth->user() AND in_array(@$this->params['prefix'], $prefix_array)) { $this->layout = 'admin'; } else { $this->layout = 'default';}
- 我应该在bootstrap或app_controller中做什么?
- 我可以动态地从DB中读取前缀,设置为$ prefix_array
- 将它们写入Configure :: write('Routing.prefixes')
答案 0 :(得分:0)
在您的app控制器中,只需加载前缀:
var $uses = array('Prefix');
function beforeFilter() {
$prefixes = $this->Prefix->find('list');
if($this->Auth->user() && in_array($this->params['prefix'], $prefixes) {
$this->layout = 'admin';
}
}