2015-08-04 22:37
浏览 41


I am getting this very strange error "Cannot use a scalar value as an array" neither google god nor stuffs on SOF helped me this what i am trying to do is i have already created user session[with session data username and password] now after user login on my_profile page i am appending some session data like user_id then i start getting this error??? Any help or Hints



      class My_profile extends CI_Controller {

      public function __construct()
        //    $this->is_login();

      public function index () {

      if($this->session->userdata('is_login')) {

       $session_data = $this->session->userdata('is_login');
       $session_data['user_id'] = $this->session->userdata('user_id');
       $this->session->set_userdata("is_login", $session_data);

     // $this->load->view('footer');
     }else {
        echo "you don't have permission to access this page <a href=../Homecontroller/index/>Login</a>";






      class My_profilee extends CI_Model {

       function __construct()
          // Call the Model constructor

      public function view_data() {

        //echo $this->session->userdata('user_id');
        return $query->result();



what i am really trying to do is to add user id [from databse] of user after login into session data and then display user information according to user id??

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongping4273 2015-08-04 22:38

    This is pretty straight forward.

    You have an assignment wherein a single value, be it an integer or string, is assigned to a variable:

    $session_data = $this->session->userdata('is_login');

    This is now a scalar value. it is unmutable unless redefined in context. You cannot apply an array value to an existing scalar value, you must instantiate a new array, and apply the value as an index, then add the new item as an index to the new array.

    $session_array['session_data'] = $this->session->userdata('is_login');

    And continue assigning variables to this array and so forth.

    解决 无用
    打赏 举报

相关推荐 更多相似问题