Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter-从帮助文件访问变量-不是类_Php_Codeigniter 2 - Fatal编程技术网

Php Codeigniter-从帮助文件访问变量-不是类

Php Codeigniter-从帮助文件访问变量-不是类,php,codeigniter-2,Php,Codeigniter 2,我有一个助手文件,它有一个变量,我想传递给一个视图,但它是空的,所以我有点不确定我是否有正确的代码,或者我以后重写了它,尽管我肯定没有 无论如何,假设helper文件中的变量是一个包含数据列表的数组,我使用: $this->load->helper('helperfile_helper'); //contains the variable 'productList' $data['productList'] = $productList; $this->load->vie

我有一个助手文件,它有一个变量,我想传递给一个视图,但它是空的,所以我有点不确定我是否有正确的代码,或者我以后重写了它,尽管我肯定没有

无论如何,假设helper文件中的变量是一个包含数据列表的数组,我使用:

$this->load->helper('helperfile_helper'); //contains the variable 'productList'
$data['productList'] = $productList;
$this->load->view('page', $data);

我希望在调用帮助程序后,帮助程序文件可以像“包含”一样使用已定义的变量,这是案例还是我遗漏了什么??

帮助程序
允许您在控制器中使用
函数
,请查看以下内容:

因此,必须在助手文件中创建一个函数,该函数将返回一个值

例如,在助手中:

if( ! function_exists('random_number'))
{
    function random_number()
    {
return 4;
    }
}
在控制器中,您可以使用它:

$this->load->helper('helperfile_helper'); //contains the variable 'productList'
$data['random_number'] = random_number();
$this->load->view('page', $data);

因此,
$data['random_number']
将包含4个帮助程序

允许您在控制器中使用
功能
,请查看以下内容:

因此,必须在助手文件中创建一个函数,该函数将返回一个值

例如,在助手中:

if( ! function_exists('random_number'))
{
    function random_number()
    {
return 4;
    }
}
在控制器中,您可以使用它:

$this->load->helper('helperfile_helper'); //contains the variable 'productList'
$data['random_number'] = random_number();
$this->load->view('page', $data);

因此,
$data['random_number']
将包含4个

我们可以看到
helperfile_helper
的代码吗?这只是一个示例,但基本上它包含一个预定义变量列表,例如$productList=array(blah=>blah);我们能看到
helperfile\u helper
的代码吗?这只是一个例子,但基本上它包含一个预定义变量列表,比如$productList=array(blah=>blah);先生,你是一颗钻石,如果我有足够的代表,我一定会投你一票!很高兴它帮助了你:)+1“所以你必须在你的助手文件中创建一个函数,它将返回一个值。”这意味着助手不能访问我的控制器变量,反之亦然。先生,你是一个钻石,如果我有足够的代表,我一定会投你一票!很高兴它帮助了您:)+1“所以您必须在助手文件中创建一个函数,该函数将返回一个值。”这意味着助手无法访问我的控制器变量,反之亦然。