2017-07-07 20 views
0

我有left_sidebar.php文件,其中我通过变量$ content回显所有的left_sidebar.php内容,在通过php include('left_sidebar.php')在index.php文件中包含left_sidebar.php之后,这里的问题是我在left_sidebar.php文件中使用的变量$ content在index.php视图中导致了undefined的问题。包含一个页面(有数据)到另一个页面,但没有任何控制器提供的数据导致变量undeign问题codeigniter

控制器

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); 

} 

该控制器提供数据,以正确left_sidebar.php文件。 但我的问题是,当我将这个left_sidebar包含在index.php中作为include(left_sidebar.php)文件时,它在第20行left_sidebar.php中给出了未定义的变量searchingtype。

这里是我的index.php代码:

+1

酷。现在告诉我们问题并显示你的代码。 –

+0

我有一个控制器提供数据到left_sidebar页面,left_sidebar页面中使用的变量不工作在index.php页面中,我通过include('left_sidebar.php')包含了这个left_sidebar。 – Bangash

+2

欢迎来到Stack Overflow。在提出问题之前,请阅读[\ [如何询问最小,完整,可验证的示例]](https://stackoverflow.com/help/mcve)。 – sjsam

回答

0

首先查看页面

print_r($searchingtype)

exit上;

并执行code.So你可以在视图中哪些数据传递

感谢

+0

$ this-> load-> view('left_sidebar.php',$ content); print_r($ searchingtype); exit;页面left_sidebar.php,这是正确的打印数据在这个页面上我的问题是当我包括(left_sidebar.php)在任何其他(在我的情况下,我已经包括index.php页面left_sidebar.php)页,然后它给未定义的变量$ searchingtype 。 Priyanka Sankhala – Bangash

+0

如果你想将此页面添加到其他视图中,你不能直接包含这个页面,你需要遵循完整的方法 $ content ['searchingtype'] =(array)json_decode ($数据1,真正的); $ this-> load-> view('left_sidebar.php',$ content); $ this-> load-> view('other_page.php'); –

+0

是的,目前我有相同的方法,你已经提到,但我试图做的方法将是最小和'干'代码的好方法。 感谢您的回复。 – Bangash

相关问题