Welcome Guest, Not a member yet? Register   Sign In
[Solved] stuck model id issue
#1

(This post was last modified: 03-19-2015, 04:57 PM by wolfgang1983.)

I am trying to be able to get the user group id from my database table, where the $name and $controller variable should work.

Instead when I add my second parameter in the $this->getID() it throws error.

A PHP Error was encountered

Severity: Notice
Message: Array to string conversion
Filename: user/users_group_update.php
Line Number: 45

Line 45 below

PHP Code:
'edit' => site_url('admin/users_group_controller_update') .'/'$this->getId($this->uri->segment(3), $controller

I know its in array but how can I fix it so can work. uri segment 3 returns the user group name. its all on the one controller at the moment the model stuff on controller just for testing.


PHP Code:
<?php

class Users_group_update extends Admin_Controller {

public function 
__construct() {
parent::__construct();
$this->load->model('admin/user/model_user_group');
}

public function 
index() {

$data['title'] = "Users Group Update";

// uri segment 3 returns user group name
// gets installed controllers
$controller_files $this->getInstalled($this->uri->segment(3)); 

$data['controller_files'] = array();

$files glob(FCPATH 'application/modules/admin/controllers/*/*.php');

if (
$files) {

foreach (
$files as $file) {
$controller  basename(strtolower($file), '.php');

$do_not_list = array(
'customer_total',
'dashboard',
'footer',
'header',
'login',
'logout',
'menu',
'online',
'permission',
'register',
'user_total'
); 

if (!
in_array($controller$do_not_list)) {

$data['controller_files'][] = array(
'name' => $controller,
'installed' => in_array($controller$controller_files),
'edit' => site_url('admin/users_group_controller_update') .'/'$this->getId($this->uri->segment(3), $controller)
);

}
                
}


}

$this->load->view('template/user/users_group_form_update'$data);

}


public function 
getId($name$controller) {

$this->db->select();
$this->db->from($this->db->dbprefix 'user_group');
$this->db->where('name'$name);
$this->db->where('controller'$controller);
$query $this->db->get();
        
return $query->row('user_group_id');
}

public function 
getInstalled($name) {

$controller_data = array();

$this->db->select();
$this->db->from($this->db->dbprefix 'user_group');
$this->db->where('name'$name);
$query $this->db->get();

foreach (
$query->result_array() as $result) {
$controller_data[] = $result['controller'];
}

return 
$controller_data;

 
}


There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

Problem solved I had to use db query inside my in_array to make it work with out errors showing

PHP Code:
<?php

class Users_group_update extends Admin_Controller {

    public function 
__construct() {
        
parent::__construct();
        
$this->load->model('admin/user/model_user_group');
    }

    public function 
index() {

        
$data['title'] = "Users Group Update";

        
$controller_files $this->getInstalled($this->uri->segment(3)); 

        
$data['controller_files'] = array();

        
$files glob(FCPATH 'application/modules/admin/controllers/*/*.php');

        if (
$files) {

            foreach (
$files as $file) {
                
$controller  basename(strtolower($file), '.php');

                
$do_not_list = array(
                    
'customer_total',
                    
'dashboard',
                    
'footer',
                    
'header',
                    
'login',
                    
'logout',
                    
'menu',
                    
'online',
                    
'permission',
                    
'register',
                    
'user_total'
                
); 

                if (!
in_array($controller$do_not_list)) {

                    
$this->db->where('name'$this->uri->segment(3));
                    
$this->db->where('controller'$controller);
                    
$query $this->db->get($this->db->dbprefix 'user_group');

                    if (
$query->num_rows()) {

                    
$row $query->row();

                    
$data['controller_files'][] = array(
                        
'name' => $controller,
                        
'installed' => in_array($controller$controller_files),
                        
'edit' => site_url('admin/users_group_controller_update' .'/'$row->user_group_id)
                    );

                    }
                }
            }
        }

        
$this->load->view('template/user/users_group_form_update'$data);
    }

    public function 
getInstalled($name) {
        
$controller_data = array();

        
$this->db->select();
        
$this->db->from($this->db->dbprefix 'user_group');
        
$this->db->where('name'$name);
        
$query $this->db->get();

        foreach (
$query->result_array() as $result) {
            
$controller_data[] = $result['controller'];
        }

        return 
$controller_data;
    }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB