Welcome Guest, Not a member yet? Register   Sign In
Need some idea
#1
Lightbulb 

Hi All,

I want call database like below,
right now I manually add.

PHP Code:
function get_permission_conditions()
{

 
   return array(
 
       'dashboard' => array(
 
           'View' => true,
 
           'ViewOwn' => true,
 
           'Edit' => true,
 
           'Create' => true,
 
           'Delete' => true
        
),
 
       'users' => array(
 
           'View' => true,
 
           'ViewOwn' => false,
 
           'Edit' => true,
 
           'Create' => true,
 
           'Delete' => true,
 
       ),
 
       'user_plans' => array(
 
           'View' => false,
 
           'ViewOwn' => false,
 
           'Edit' => false,
 
           'Create' => true,
 
           'Delete' => true,
 
       ),
 
       'roles' => array(
 
           'View' => true,
 
           'ViewOwn' => false,
 
           'Edit' => true,
 
           'Create' => true,
 
           'Delete' => true
        
),
 
       'user_groups' => array(
 
           'View' => true,
 
           'ViewOwn' => false,
 
           'Edit' => false,
 
           'Create' => false,
 
           'Delete' => false
        
),
 
       'ip_blocking' => array(
 
           'View' => true,
 
           'ViewOwn' => false,
 
           'Edit' => true,
 
           'Create' => false,
 
           'Delete' => false
        
),
 
       'currencies' => array(
 
           'View' => true,
 
           'ViewOwn' => false,
 
           'Edit' => true,
 
           'Create' => true,
 
           'Delete' => true
        
),
 
       'email_templates' => array(
 
           'View' => true,
 
           'ViewOwn' => false,
 
           'Edit' => true,
 
           'Create' => true,
 
           'Delete' => true
        
),
 
       'custom_fields' => array(
 
           'View' => true,
 
           'ViewOwn' => false,
 
           'Edit' => true,
 
           'Create' => true,
 
           'Delete' => true
        
),
 
       'logs' => array(
 
           'View' => true,
 
           'ViewOwn' => false,
 
           'Edit' => true,
 
           'Create' => true,
 
           'Delete' => true
        
),
 
       'settings' => array(
 
           'View' => true,
 
           'ViewOwn' => false,
 
           'Edit' => true,
 
           'Create' => false,
 
           'Delete' => false
        
),
 
       'staff' => array(
 
           'View' => true,
 
           'ViewOwn' => false,
 
           'Edit' => true,
 
           'Create' => true,
 
           'Delete' => true
        
)
 
   );



Database
[Image: 5EpJC2XzQEieCTP4Z-jjrg.png]


Example:
How to make enableView == 1 as true
PHP Code:
function get_permission_conditions()
{
    $CI =& get_instance();
    
    $permissions 
$CI->db->get('permissions');
    
    
return array(
        foreach($permissions->array_result() as $p) {
            $p['shortname'] => array(
                'View' => true,
                'ViewOwn' => true,
                'Edit' => true,
                'Create' => true,
                'Delete' => true
            
),
        }
    );


Thanks you....
Reply
#2

Remember to put database function inside a model, not a library.
A model doesn't need the & get_instance(), you can refer to $this.

So, in your model, make this function:

PHP Code:
function get_permission_conditions()
{
 
 $permissions $this->db->get('permissions');
 
 $rv = array();
 
 foreach($permissions->result() as $p) {
 
    $rv[$p->shortname] = array(
 
      'View' => $p->enableView,
 
      'ViewOwn' => $p->enableViewOwn,
 
      'Create'=> $p->enableCreate,
 
      'Edit' => $p->enableEdit,
 
      'Delete' => $p->enableDelete,
 
   );
 
 }
 
 return $rv;

Reply
#3

Its working now!! thanks you so much!!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB