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.

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

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向