[英]in_array() expects parameter 2 to be array, string given
I'm building a CodeIgniter application with SQL server. 我正在使用SQL Server构建CodeIgniter应用程序。
I' reading user permission from the database and then store it so I can show sidebar menu according to the user permission but I'm getting this error : 我正在从数据库中读取用户权限,然后将其存储,因此我可以根据用户权限显示侧边栏菜单,但出现此错误:
in_array() expects parameter 2 to be array, string given
in_array()期望参数2为数组,给定字符串
here's my controller code: 这是我的控制器代码:
public function __construct()
{
parent::__construct();
$group_data = array();
if(empty($this->session->userdata('logged_in'))) {
$session_data = array('logged_in' => FALSE);
$this->session->set_userdata($session_data);
}
else {
$user_id = $this->session->userdata('id');
$this->load->model('model_groups');
$group_data = $this->model_groups->getUserGroupByUserId($user_id);
preg_replace_callback('!s:(\d+):"(.*?)";!',
function($match) {
return ($match[1] == strlen($match[2])) ? $match[0] : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';},
$group_data['permission'];);
$this->data['user_permission'] = $group_data['permission'];
var_dump($this->data['user_permission']);
$this->permission = $group_data['permission'] ;
}
}
When I try to show what's stored in my data var_dump($this->data['user_permission']); 当我尝试显示存储在数据中的内容时,var_dump($ this-> data ['user_permission']); I get :
我得到:
and I'm trying to use them in my view like this: 我试图像这样在我的视图中使用它们:
<?php if(in_array('createUser', $this->data['user_permission']) || in_array('updateUser', $this->data['user_permission']) || in_array('viewUser', $this->data['user_permission']) || in_array('deleteUser', $this->data['user_permission'])): ?>
<li class="treeview" id="userSideTree">
<a href="#">
<i class="fa fa-users"></i>
<span>Utilisateurs</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
</a>
Can you help me with this? 你能帮我吗?
You have a serialized string and the quotes are escaped. 您有一个序列化的字符串,并且引号已转义。 Strip the slashes and unserialize:
去除斜线并反序列化:
$this->data['user_permission'] = unserialize(stripslashes($group_data['permission']));
You didn't show the entire string so there could be other problems with it. 您没有显示整个字符串,因此可能还有其他问题。 Text instead of image would help.
文字而不是图像会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.