2013-03-19 54 views
1

這是我想要做的。 我希望我的左菜單基於組。如果我已將權限授予組以查看菜單,則該組應可見。CodeIgniter獨特的功能不起作用

現在在進一步討論細節。 我想告訴你我到底做了些什麼,以及在哪裏應用這個特定的菜單組權限。

這是基本控制器在覈心文件夾中命名爲My_Controller.php

我的Main控制器從My_Controller延伸。

這裏是My_Controller編碼。

<?php 
/** 
* Created by JetBrains PhpStorm. 
* User: SBPS 
* Date: 3/13/13 
* Time: 4:55 PM 
* To change this template use File | Settings | File Templates. 
*/ 

class My_Controller extends CI_Controller{ 
    function __construct(){ 
     parent::__construct(); 
    } 
    public function UserGroups(){ 
     $UserID=1; 
     $this->load->model('ui_components/Left_menu_cpanel'); 
     $Groups=$this->Left_menu_cpanel->get_user_groups($UserID); 
     return $Groups; 
    } 
} 

這是我的Main控制器。

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Main extends My_Controller { 
    /* 
    * Main Controller 
    * Designed By: Kifayat Ullah 
    * Purpose: To work as a main Control Panel for the Authenticated users 
    */ 


    public function index() { 
     if(!$this->session->userdata('UserID') 
     || $this->session->userdata('UserID')<=0){ 
      redirect('user_management/login_form'); 
     }// end of session check 
     // Prepare the LeftHandSide Menu Object and Send it to the View for Display 
     $this->load->model('ui_components/Left_menu_cpanel'); 
     $UserGroups=$this->UserGroups(); 

     // retrive menu List object 


     // Pass the name of the view that you want to load 
     $data['main_container']='tamplet_includes/tamplet_main_container_tags'; 
     $data['UserGroups']=$UserGroups; 
     //$data['UserGroups']=$this->UserGroups(); 
     $this->load->view('SystemView',$data); 

     //var_dump($UserGroups); 
    } 

    function UserAdditionForm(){ 

     echo 'hello'; 
    } 

} 

/* End of file welcome.php */ 
/* Location: ./application/controllers/welcome.php */ 

現在它的模型轉向。

我的基本模型命名爲My_Model.php在Core Folder中。 我的left_menu_cpanelMy_Model.php延伸。

My_Model.php基本模型文件:

<?php 
/** 
* Created by JetBrains PhpStorm. 
* User: SBPS 
* Date: 3/19/13 
* Time: 3:13 PM 
* To change this template use File | Settings | File Templates. 
*/ 

class My_Model extends CI_Model{ 
    function __construct(){ 
     parent::__construct(); 
    } 

    public function get_user_groups($UserID){ 
     //$UserID=1; // We will Update this UserID Later 
     $this->load->helper('security'); 
     $this->db->select('*'); 
     $this->db->from('sys_user_accounts'); 
     $this->db->join('sys_user_groups_memberships', 'sys_user_groups_memberships.UserID = sys_user_accounts.UserID', 'INNER'); 
     $this->db->where('sys_user_accounts.UserID', $UserID); 
     $this->db->join('sys_user_groups', 'sys_user_groups.GroupID = sys_user_groups_memberships.GroupID', 'INNER'); 
     $query = $this->db->get(); 

     return $query->result(); // return all forms list 

    } 
} 

left_menu_cpanel.php型號文件:

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Left_menu_cpanel extends My_Model { 
    function __construct() 
    { 
     parent::__construct(); 
    } 

    // This function returns true if a user authenticaton is successfull 
    public function get_left_menu_items($GroupID){ 
     //$GroupID=1; // We need update this to a Group Array from the users permissions list 
     $this->load->helper('security'); 
     $this->db->distinct(); 
     $this->db->select('*'); 
     $this->db->from('sys_group_roles_forms_view'); 
     $this->db->where('GroupID', $GroupID); 
     $query = $this->db->get(); 

     return $query->result(); // return all forms list  

    }// end of authenticate function 
}//end of class 
/* End of file left_menu_cpanel.php.php */ 
/* Location: ./application/models/user_management/left_menu_cpanel.php.php */ 
?> 

我的表結構sys_group_roles_forms_view enter image description here

sys_user_groups enter image description here

用戶可以屬於多個組,並且一個組可以擁有許多用戶。

現在,我想我已經發布了每一個細節,

所以我的問題是,如果我給組權限查看某些選項卡,所以如果我是獲准在兩個或多個組,只有標籤應該出現一次。

但是,由於用戶屬於3個不同的組,所以這樣做的理由是它重複Tab 3次。但我只需要一次。

按Tab我的意思是左側菜單重複三次。 enter image description here

我試圖通過網絡搜索解決方案,我得到了它的獨特功能的解決方案。但是這個功能在我嘗試的時候不起作用。

請讓我瞭解爲什麼該功能不工作,如果它能在我的方案中工作,那麼如何應用該功能?

回答

2

區別於整行,包括組ID等。您只需選擇所需的列(避免select *),並使用group_by()方法。

+0

正好。但我慢了:-) – Natrium 2013-03-19 14:19:25

+0

請你能解釋一下在我的查詢中如何使用group_by()? – 2013-03-19 16:13:21

+0

我使用了group_by('GroupID'); 但它沒用。我仍然得到同樣的問題? 如何解決? – 2013-03-19 17:10:51