doutui7955 2017-03-11 09:14
浏览 43

如何在codeigniter中调用函数内部函数

I want to call the function inside function through the url but i am getting the blank page using this code.

Here is my php code

public function womens()
{
    function undergarments()
    {
        $this->headerplace();
        $this->menuplace();
        $id = '1';
        $query['result'] = $this->Products_model->showwomensubcat($id);
        $this->load->view('womens', $query);
        $this->footerplace();
    }
}

Here is Html:

<a href="<?php echo base_url().'products/womens/undergarments';?>">Garments</a>
  • 写回答

1条回答 默认 最新

  • doudou3935 2017-03-11 10:13
    关注

    Try something like this

    public function women()
    {
      $cat=$this->uri->segment(3);         // now send undergarments here
      $data['items']=$this->Products_model->getItemsByCat($cat);
    
      $this->load->view('header');
      $this->load->view('menu');
      $this->load->view('women',$data);
      $this->load->view('footer');
    }
    

    The way you were doing above in your post, how many function will you create in case you have hundreds of sub-categories. Make things dynamic. With the code above you can send any category. You can even enhance it by using routes or create fancy URLs by using routes but so far what you have asked. the above code is your solution. Just define the function in your model to get your data like

    public function getItemsByCat($cat)
    {
       return $this->db->select('*')->from('items')->WHERE('cat',$cat)->get()->result_array();
    }
    

    and then render your view

    Edit

    <a href="<?php echo base_url().'products/womens/undergarments';?>">Garments</a>
    

    Above URL means, your controller name is products, your function name is womens and you are sending the parameter undergarments in url so when you click the link Garments you will be taken to women function of products controller which will fetch all records of undergarments category

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度