开发者

How to write routing prefixes dynamically from DB

开发者 https://www.devze.com 2023-02-27 02:49 出处:网络
i have db table with the prefixes and need them to be readable in app_controller beforeFilter $prefix_array = array(\'admin\', \'marketing\');

i have db table with the prefixes and need them to be readable in 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->lay开发者_如何学JAVAout = 'default';}

-where should i do it in bootstrap or app_controller?

-how can i dynamically read prefix from DB, set to $prefix_array

-write them to Configure::write('Routing.prefixes')


In your app controller, just load the prefixes:

var $uses = array('Prefix');

function beforeFilter() {
    $prefixes = $this->Prefix->find('list');
    if($this->Auth->user() && in_array($this->params['prefix'], $prefixes) {
        $this->layout = 'admin';
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消