douxin5953 2016-09-10 19:32
浏览 43

关系codeigniter,codeigniter-base-model

:)

I have a problem with relationships in codeigniter , I'm doing a small blog.

the problem is that I need in the post by the user ID called the USERNAME that created the post .

but I can not do it step my code , I hope you can help me

controller

  public function show($post = NULL)
{
  $this->load->model('post_model', 'posts_model');
  $this->load->helper('url');
  $postid = $this->uri->segment(4);
  $post = $this->posts_model->get_by('id', $postid);
  $this->data = array(
      'title' => 'Posts',
      'subtitle' => 'Post',
      'navClass' => 'tofront blue-bar',
      'subnavClass' => 'toback blue-bar',
      'isfab' => true,
      'message' => $this->session->flashdata('message'),
      'posts_call' => $post,
      'current' => current_url(),
      'sidebar' => true,
  );

  $this->session->set_userdata('last_page', current_url());
  $this->theme->render('post/show', $this->data);
}

model

class Post_model extends SP_Model
{
  public $belongs_to = array( 'post' => array( 'primary_key' => 'post_author' )  );
}

DB:

Foreign key post_author

need relation with id

thanks in advance! :D

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
    • ¥20 matlab yalmip kkt 双层优化问题
    • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
    • ¥88 实在没有想法,需要个思路
    • ¥15 MATLAB报错输入参数太多
    • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
    • ¥15 有赏,i卡绘世画不出
    • ¥15 如何用stata画出文献中常见的安慰剂检验图