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.

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

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 flask项目,怎么使用AJAX传数据库数据到echarts图表的data里,实现异步加载数据。
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题