【问题标题】:CodeIgniter DataMapper ORM include_related always returning first row in database tableCodeIgniter DataMapper ORM include_related 总是返回数据库表中的第一行
【发布时间】:2012-03-21 13:40:17
【问题描述】:

我有一个用户模型和一个 user_profile 模型,我正在尝试使用以下函数获取特定用户和相关的 user_profile。如果我注释掉 include_related 行,它可以工作并根据 user_id 获取用户,但如果我尝试使用 include_related 来拉入用户配置文件字段,它只会返回数据库中的第一个用户,而不是基于 user_id 的用户。这里出了什么问题?

function edit_admin_user(){
    //check user is logged in and has admin rights
    $this->login_manager->check_login(1);
    //get user id from the uri segment
    $user_id = $this->uri->segment(3);

    $user = new User();
    $user->get_by_id($user_id);
    //$user->include_related('user_profile', array('firstname','surname', 'telephone', 'address1', 'address2', 'city', 'postcode'), TRUE, TRUE)->get();

    //set the content for the view partial (this is the actual content of the page)
    $content_data['user'] = $user;

    $data['content'] = $this->load->view('admin/edit_admin_user', $content_data, TRUE);
    $data['page_title'] = 'Get Stuffed | Admin Area | Edit Admin User';

    $this->load->view('admin/index', $data);
}

【问题讨论】:

    标签: php codeigniter codeigniter-2 codeigniter-datamapper


    【解决方案1】:

    应该是有精神障碍:

     $user = new User();
        $user->where('id', $user_id);
        $user->include_related('user_profile', array('firstname','surname', 'telephone',   'address1', 'address2', 'city', 'postcode'), TRUE, TRUE)->get();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-17
      • 2021-11-17
      • 1970-01-01
      相关资源
      最近更新 更多