0

I have left_sidebar.php file where i have echo all the left_sidebar.php content through variable $content, after including left_sidebar.php in index.php file through php include ('left_sidebar.php'), the issue here is that the variables $content that i have used in left_sidebar.php file causing issue of undefined on index.php view.

Controller

public function LeftSidebarData()
{
    $url1 = 'url to pick the data';
    $curl_hand = curl_init($url1);
    curl_setopt($curl_hand, CURLOPT_TIMEOUT, 5);
    curl_setopt($curl_hand, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($curl_hand, CURLOPT_RETURNTRANSFER, true);
    $data1 = curl_exec($curl_hand);
    curl_close($curl_hand);
    $content['searchingtype'] = (array) json_decode($data1,true);

    $this->load->view('left_sidebar.php',$content);

}

This controller is providing data to left_sidebar.php file correctly. but My problem is when i include this left_sidebar in index.php as include(left_sidebar.php) file it gives undefined variable searchingtype on line 20 left_sidebar.php.

here is my index.php code:

Bangash
  • 117
  • 9
  • 1
    Cool. And now tell us the question and show your code. – u_mulder Jul 07 '17 at 13:52
  • I have controller with a method that provide data to left_sidebar page, the variable used in left_sidebar page not working in index.php page where i have included this left_sidebar through include ('left_sidebar.php'). – Bangash Jul 07 '17 at 13:56
  • 2
    Welcome to Stack Overflow. Before asking questions please read [\[ How to ask minimal, complete, verifiable example \]](https://stackoverflow.com/help/mcve). – sjsam Jul 07 '17 at 13:58
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – MC Emperor Jul 10 '17 at 11:07

1 Answers1

0

First of all on view page

print_r($searchingtype)

exit;

and execute the code.So you can get what data pass in view

Thanks

Priyanka Sankhala
  • 808
  • 1
  • 9
  • 25
  • $this->load->view('left_sidebar.php',$content); print_r($searchingtype);exit; page left_sidebar.php, It's print data correctly on this page my problem is when i include(left_sidebar.php) in any other (in my case i have include left_sidebar.php in index.php page) page then it gives undefined variable $searchingtype. Priyanka Sankhala – Bangash Jul 10 '17 at 06:28
  • You can't direct include ` include(left_sidebar.php)` like this if you want to add this page into other view you need to follow complete method $content['searchingtype'] = (array) json_decode($data1,true); $this->load->view('left_sidebar.php',$content); $this->load->view('other_page.php'); – Priyanka Sankhala Jul 10 '17 at 09:05
  • yes currently i have same method that you have mention but the method i am trying to do will be good for minimality and 'dry' code. thanks for your reply. – Bangash Jul 10 '17 at 09:21