doufu2396 2015-08-04 22:37
浏览 41
已采纳

在codeigniter中不能使用标量值作为数组?

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

//controller

<?php 


      class My_profile extends CI_Controller {

      public function __construct()
         {
              parent::__construct();
              $this->load->library('session');
              $this->load->helper('form');
              $this->load->helper('url');
              $this->load->helper('html');
              $this->load->database();
              $this->load->library('form_validation');
        //    $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->model('My_profilee');
      $data['query']=$this->My_profilee->view_data();
      $this->load->helper('url');
      $this->load->view('header2');
      $this->load->view('my_profile');
     // $this->load->view('footer');
     }else {
        echo "you don't have permission to access this page <a href=../Homecontroller/index/>Login</a>";
        die();

     }
      }



}

      ?>

//model

<?php 


      class My_profilee extends CI_Model {

       function __construct()
     {
          // Call the Model constructor
          parent::__construct();
          $this->load->database(); 
     }


      public function view_data() {


        //echo $this->session->userdata('user_id');
        $query=$this->db->get('tbl_usrs');
        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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1