doumei8258 2015-03-19 15:43
浏览 26
已采纳

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

On my controller I have a error on this line 'edit' => site_url('admin/users_group_controller_update') .'/'. $this->getId($controller)

When I refresh my page it throws the error Array to string conversion

A PHP Error was encountered Severity: Notice Message: Array to string conversion Filename: user/users_group_update.php Line Number: 47

Not sure what to do on that because I need to add variable $controller in to $this->getId($controller);

What changes is best suited to make this work.

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

View

<?php echo Modules::run('admin/common/header/index');?>

<div id="wrapper">
<?php echo Modules::run('admin/common/menu/index');?>
<div id="page-wrapper" >
<div id="page-inner">

<?php 

$data = array(
'class' => 
'form-horizontal', 
'id' => 
'form-users-group'
);
echo form_open_multipart('admin/users_group_update' .'/'. $this->uri->segment(3), $data);?>

<div class="panel panel-default">
<div class="panel-heading clearfix">
<div class="pull-left" style="padding-top: 7.5px"><h1 class="panel-title"><?php echo $title;?></h1></div>
<div class="pull-right">
<a href="<?php echo base_url('admin/users_group');?>" class="btn btn-primary">Cancel</a>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
<div class="panel-body">

<?php echo validation_errors('<div class="alert alert-warning text-center">', '</div>'); ?>

<div class="form-group">
<?php 
$data = array(
'class' => 'col-sm-2'
);
echo form_label('User Group Name', 'name', $data)
;?>
<div class="col-sm-10">
<?php 
$data = array(
'id' => 'name', 
'name' => 'name', 
'class' => 'form-control', 
'value' => set_value('name')
);
echo form_input($data)
;?>
</div>
</div>

<table class="table table-striped table-bordered">
<thead>
    <tr>
        <td>Controller Name</td>
        <td>Access</td>
        <td>Modify</td>
    </tr>
</thead>
<tbody>
<?php if ($controller_files) { ?>
<?php foreach ($controller_files as $controllers) { ?>
<tr>

<td>
<div class="clearfix">

<div class="pull-left">
<?php echo $controllers['name']; ?>
</div>

<div class="pull-right">

<?php if ($controllers['installed']) { ?>
<span class="label label-success">Installed</span>
<span class="label label-danger"><a style="color: #FFF; text-decoration: none;" href="<?php echo $controllers['edit'];?>">Edit Individual Controller</a></span>
<?php } else { ?>
<span class="label label-primary">Not Installed</span>
<?php } ?>

</div>

</div>

</td>

</tr>
<?php } ?>
<?php } ?>
</tbody>
</table>


</div>
<div class="panel-footer">
</div>
</div><!-- Panel End -->
<?php echo form_close();?>

</div><!-- # Page Inner End -->
</div><!-- # Page End -->

</div><!-- # Wrapper End -->
<?php echo Modules::run('admin/common/footer/index');?>
  • 写回答

2条回答 默认 最新

  • dspv70887 2015-03-19 23:54
    关注

    With in my files variable I had to use the db function to get it to work. No errors show now all fixed.

    <?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;
    }
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?