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.

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

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵