model unserialize for user group error

时间:2014-10-16 08:59:22

标签: php codeigniter

我的模型上有错误我正在努力解决我unserialize($query->row('permission'))但由于某种原因我收到错误。

对我来说似乎无法解决这个问题。不知道该怎么做或如何解决它。

A PHP Error was encountered
Severity: Warning
Message: unserialize() expects parameter 1 to be string, array given
Filename: user/users_group_model.php
Line Number: 16

获取用户组模型功能

public function getUserGroup($user_group_id) {
$query = $this->db->query("SELECT DISTINCT * FROM " . $this->db->dbprefix . "user_group WHERE user_group_id = '" . (int)$user_group_id . "'");

$user_group = array(
'name' => $query->row('name'),
'permission' => unserialize($query->row('permission'))
);

return $user_group;
}

控制器功能

public function getForm() {
    $data['heading_title'] = $this->lang->line('heading_title');

    $data['text_select_all'] = $this->lang->line('text_select_all');
    $data['text_unselect_all'] = $this->lang->line('text_unselect_all');

    $data['entry_name'] = $this->lang->line('entry_name');
    $data['entry_access'] = $this->lang->line('entry_access');
    $data['entry_modify'] = $this->lang->line('entry_modify');

    $data['button_save'] = $this->lang->line('button_save');
    $data['button_cancel'] = $this->lang->line('button_cancel');

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

    $data['breadcrumbs'][] = array(
        'text' => $this->lang->line('text_home'),
        'href' => site_url('admin/dashboard')
    );

    $data['breadcrumbs'][] = array(
        'text' => $this->lang->line('heading_title'),
        'href' => site_url('admin/users_group')
    );

    $data['cancel'] = site_url('admin/users_group');

    $user_group_id = $this->uri->segment(4);
    $data['user_group_id'] = $user_group_id;

    $user_group_info = $this->users_group_model->getUserGroup($user_group_id);

    if (isset($this->request->post['name'])) {
        $data['name'] = $this->request->post['name'];
    } elseif (!empty($user_group_info)) {
        $data['name'] = $user_group_info['name'];
    } else {
        $data['name'] = '';
    }

    $this->load->model('admin/user/users_group_model');

    $ignore = array(
        'blank',
        'dashboard',
        'column_left',
        'menu',
        'startup',
        'login',
        'logout',
        'forgotten',
        'reset',
        'not_found',
        'permission',
        'footer',
        'header'
    );

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

    $files = glob(APPPATH . 'modules/admin/' . 'controllers/*/*.php');

    foreach ($files as $file) {
        $part = explode('/', dirname($file));

        $permission = basename($file, '.php');

        if (!in_array($permission, $ignore)) {
            $data['permissions'][] = $permission;
        }
    }

    $this->load->library('request');


    if (isset($this->request->post['permission']['access'])) {
        $data['access'] = $this->request->post['permission']['access'];
    } elseif (isset($user_group_info['permission']['access'])) {
        $data['access'] = $user_group_info['permission']['access'];
    } else {
        $data['access'] = array();
    }

    $this->load->view('user/users_group_form', $data);

}

1 个答案:

答案 0 :(得分:0)

我已修复问题,必须在名称区域上方添加!empty post方法,现在正在工作。它通过这种方式删除了所有错误。

public function getForm() {
    $this->load->model('admin/user/users_group_model');
    $this->load->library('request');

    $data['heading_title'] = $this->lang->line('heading_title');

    $data['text_select_all'] = $this->lang->line('text_select_all');
    $data['text_unselect_all'] = $this->lang->line('text_unselect_all');

    $data['entry_name'] = $this->lang->line('entry_name');
    $data['entry_access'] = $this->lang->line('entry_access');
    $data['entry_modify'] = $this->lang->line('entry_modify');

    $data['button_save'] = $this->lang->line('button_save');
    $data['button_cancel'] = $this->lang->line('button_cancel');

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

    $data['breadcrumbs'][] = array(
        'text' => $this->lang->line('text_home'),
        'href' => site_url('admin/dashboard')
    );

    $data['breadcrumbs'][] = array(
        'text' => $this->lang->line('heading_title'),
        'href' => site_url('admin/users_group')
    );

    $data['cancel'] = site_url('admin/users_group');

    $user_group_id = $this->uri->segment(4);
    $data['user_group_id'] = $user_group_id;

    if (!empty($user_group_id) && $this->request->server['REQUEST_METHOD'] != 'POST') {
        $user_group_info = $this->users_group_model->getUserGroup($user_group_id    );
    }

    if (isset($this->request->post['name'])) {
        $data['name'] = $this->request->post['name'];
    } elseif (!empty($user_group_info)) {
        $data['name'] = $user_group_info['name'];
    } else {
        $data['name'] = '';
    }

    $ignore = array(
        'blank',
        'dashboard',
        'column_left',
        'menu',
        'startup',
        'login',
        'logout',
        'forgotten',
        'reset',
        'not_found',
        'permission',
        'footer',
        'header'
    );

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

    $files = glob(APPPATH . 'modules/admin/' . 'controllers/*/*.php');

    foreach ($files as $file) {
        $part = explode('/', dirname($file));

        $permission = basename($file, '.php');

        if (!in_array($permission, $ignore)) {
            $data['permissions'][] = $permission;
        }
    }

    if (isset($this->request->post['permission']['access'])) {
        $data['access'] = $this->request->post['permission']['access'];
    } elseif (isset($user_group_info['permission']['access'])) {
        $data['access'] = $user_group_info['permission']['access'];
    } else {
        $data['access'] = array();
    }

    $this->load->view('user/users_group_form', $data);

}