dougao1542 2015-02-05 13:16
浏览 293

检查数据库记录是否存在Codeigniter

I have a project and have run into a problem. I use Codeigniter HMVC and therefore build modules. I appreciate your help. Thanks.

I have two module methods where one calls another. The other delivers a database result and loads it into a view that is then passed on to the template from the 1st module method. I now realize, that since I get a view and not data from the 2nd module, I don't see how I can check if there is a database record returned, and I don't want another database call just for that purpose. The seperation between "item" and "description" modules is required. Having data sent instead would make a really messy structure that to my understanding would counteract the HMVC structure. I therefore need to keep this structure. How can I check if database record exists and only run the 1st method if it does? Please advise. Thanks

1st module (controller method) called through URL

function view_item($item_id) 
{    

    $data['item_id'] = $item_id;       
    $data['item'] = $this->item;  
    $data['item_group'] = $this->item_group;  
    $data['content_module'] = Modules::run("descriptions/view",$item_id); 
    $data['active_menu_item'] = "descriptions";
    $data['view_file'] = "handle_view";
    $data['module'] = $this->module;
    $template = "application";      
    $this->load->module('templates');
    $this->load->templates->$template($data); 

}

2nd module method called by 1st module method

function view($item_id)
{
    $data['title'] = "View description";
    $data['page_title'] = "View description";
    $data['page_subtitle'] = "This item";              
    $data['item_id'] = $item_id;
    $array = array('item_id'=> $item_id,'group_id'=> $this->group_id);
    $object = $this->get_where_custom($array);
    $num_rows = $object->num_rows;
    $descriptions =  $object->result();
    $data['description'] =  $descriptions[0];
    $this->load->view('view_view',$data); 

} 
  • 写回答

1条回答 默认 最新

  • douyong8801 2015-03-02 08:36
    关注
    if(isset($data['content_module']))
    

    Would be an alternative.

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能