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 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳