0

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>
6
  • you have a syntax error Commented Mar 11, 2017 at 9:19
  • please share the code of view Commented Mar 11, 2017 at 9:21
  • 1
    There's no syntax error here, but codeigniter does not work like this. Commented Mar 11, 2017 at 9:46
  • i don't have any syntax error i just want to call the function inside the function in the url but i am getting blank page using above code Commented Mar 11, 2017 at 9:51
  • 1
    in the url you have given above, products is controller, women is function and undergarments is parameter Commented Mar 11, 2017 at 10:05

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

7 Comments

how to call a function inside a function in ci through the href?
<a href="<?php echo base_url().'products/womens/undergarments';?>">Under Garments</a> Like if i have antoher method inside womens so i will use "women/kurtis" but it's not working!!
it doesn't matter what caption you are giving to the link, its the parameter which you are sending, in this case you are sending undergarments, if there are items of this category in your products table and your query is correct then you will get the result
yes i am getting the result but how can i use the nested methods in ci method and how to call it with link?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.