Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 数组codeigniter中的字符串转换错误_Php_Codeigniter - Fatal编程技术网

Php 数组codeigniter中的字符串转换错误

Php 数组codeigniter中的字符串转换错误,php,codeigniter,Php,Codeigniter,在我的控制器上,我在这一行有一个错误“edit”=>site\u url('admin/users\u group\u controller\u update')。/'$此->getId($controller) 当我刷新页面时,它会抛出错误数组到字符串转换 遇到PHP错误严重性:注意消息:数组到字符串 转换文件名:user/users\u group\u update.php行号:47 不确定该怎么做,因为我需要在$this->getId($controller)中添加变量$controlle

在我的控制器上,我在这一行有一个错误
“edit”=>site\u url('admin/users\u group\u controller\u update')。/'$此->getId($controller)

当我刷新页面时,它会抛出错误数组到字符串转换

遇到PHP错误严重性:注意消息:数组到字符串 转换文件名:user/users\u group\u update.php行号:47

不确定该怎么做,因为我需要在
$this->getId($controller)中添加变量$controller

什么样的更改最适合于此工作。

<?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)) {

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

    $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;
}

public function getId($controller) {
    $this->db->select();
    $this->db->from($this->db->dbprefix . 'user_group');
    $this->db->where('name', $this->uri->segment(3));
    $this->db->where('controller', $controller);

    $query = $this->db->get();

    return $query->row('user_group_id');
}
}

拯救
换行

'edit' => site_url('admin/users_group_controller_update') .'/'. $this->getId($controller)


在我的文件变量中,我必须使用db函数使其工作。没有错误显示,现在全部修复

<?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;
}
} 

错误表示函数
getId()
返回的是数组而不是字符串。但您所做的应该返回列
user\u group\u id
的值。这很奇怪。你能像这样返回整行吗
return$query->row()
并使用此
$this->getId($controller)->user\u group\u id
。显示的错误仍然相同。当我点击按钮时,它会显示正确的id。你能解释一下确切的流程吗。哪个按钮?Users_group_update(用户组更新)显示已安装到数据库或是新的控制器列表,当我单击视图中的edit(编辑)按钮时,它将引导我到该控制器,我可以对其进行编辑。示例链接
http://localhost/project/admin /用户组控制器更新/127
在$data['controller\u files'][]中,我已使用站点url进行编辑。我需要最后一段来获取id,其中$this->uri段(3)是用户组的名称和get-where控制器。有点奇怪为什么显示字符串错误。我猜
id
是第四个URI参数。尝试这个
$this->uri->segment(4)
。也有同样的问题,但后来发现唯一可行的方法是在in_数组中使用codeigniter db函数,如我的回答中所示,现在可以了,没有错误。您不应该在控制器中创建数据库查询,并将所有任务放在一个方法中
'edit' => site_url('admin/users_group_controller_update' .'/'. $this->getId($controller))
<?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;
}
}