Esempio n. 1
0
 protected function _initialize()
 {
     if (!$this->is_login()) {
         $this->redirect('Public/login');
     }
     $main = get_access_menu(1);
     $this->assign("main", $main);
 }
Esempio n. 2
0
 public function product()
 {
     layout('Common/layout');
     $curt = 5;
     $menu = get_access_menu($curt);
     $this->assign("curt", $curt);
     $this->assign("menu", $menu);
     $this->display('Common/content');
 }
Esempio n. 3
0
function get_access_menu($pid = 0)
{
    $data = M('access')->where("pid=%d", $pid)->field('id,title,app,model,action,data')->select();
    foreach ($data as $value) {
        $list[$value['id']]['name'] = $value['title'];
        if ($value['model'] && $value['action']) {
            $href = $value['app'] ? $value['app'] . '/' : '';
            $href .= $value['model'] . '/' . $value['action'];
            $list[$value['id']]['href'] = U($href);
        } else {
            $list[$value['id']]['child'] = get_access_menu($value['id']);
        }
    }
    return $list;
}
Esempio n. 4
0
 public function index($model, $data, $major = 'id')
 {
     $page['page'] = I('get.page', 1, 'htmlspecialchars,number_int');
     $page['rows'] = I('get.rows', 10, 'htmlspecialchars,number_int');
     $link['rank'] = I('get.rank', '', 'htmlspecialchars');
     $link['sort'] = I('get.sort', '', 'htmlspecialchars');
     // 获取下级权限
     $ac_pwh = array($Think . MODULE_NAME, $Think . CONTROLLER_NAME, $Think . ACTION_NAME);
     $ac_pid = M('access')->where("app='%s' and model='%s' and action='%s'", $ac_pwh)->field('id')->find();
     $action = get_access_menu($ac_pid['id']);
     // 筛选条件,待添加
     $where = $data['where'];
     $path = array();
     foreach ($where as $key => $value) {
         $link[$key] = $where[$key]['value'] = I($key, $value['value'], $value['filter']);
         if ($value['type'] == 'text' && $link[$key] != '') {
             $path[$key] = array('like', '%' . $link[$key] . '%');
         } elseif ($value['type'] != 'text') {
             $path[$key] = $link[$key];
         }
     }
     // 展示字段
     $field = $data['field'];
     foreach ($field as $key => $value) {
         $url = $link;
         if (isset($value['sort'])) {
             $url['sort'] = $link['sort'] == 'asc' ? 'desc' : 'asc';
             $field[$key]['url'] = U('', array_merge($url, array('rank' => $key)));
             $field[$key]['sort'] = $key == $link['rank'] ? $link['sort'] : '';
         }
     }
     // 数据列表
     $list = array();
     $order = $link['rank'] && $link['sort'] ? array($link['rank'] => $link['sort']) : array($major => 'desc');
     $table = M($model)->where($path)->field(array_keys($field))->page($page['page'], $page['rows'])->order($order)->select();
     foreach ($table as $key => $value) {
         $list[$key]['data'] = $value;
         foreach ($data['handle'] as $handle) {
             $handle['url'] = U($handle['url'], array($handle['param'] => $value[$major]));
             $list[$key]['handle'][] = $handle;
         }
     }
     // 分页列表
     $page['count'] = M($model)->where($path)->count();
     $page['pages'] = ceil($page['count'] / $page['rows']);
     $page['first'] = U('', array_merge($link, array('page' => 1)));
     $page['last'] = U('', array_merge($link, array('page' => $page['pages'])));
     $start = max(min($page['pages'] - 8, $page['page'] - 4), 1);
     $end = min($start + 8, $page['pages']);
     $page['list'] = array();
     for ($i = $start; $i <= $end; $i++) {
         $page['list'][$i] = U('', array_merge($link, array('page' => $i)));
     }
     $this->assign("action", $action);
     $this->assign("batchs", $data['batchs']);
     $this->assign("field", $field);
     $this->assign("where", $where);
     $this->assign("list", $list);
     $this->assign("page", $page);
     $this->display('Common/table');
 }