我想从helper获取数组到控制器,但它对我不起作用。这是我的代码。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function tamplate_function()
{
$navigaton_site=array("Header","Sidebar","Body","Footer");
return $navigaton_site;
}
$this->load->helper('tamplate_helper' );
$data['tamplate_array'] = $this->tamplate_function();
var_dump($data);
答案 0 :(得分:3)
不要使用$ this关键字。尝试 -
$this->load->helper('tamplate_helper' );
$data['tamplate_array'] = tamplate_function();
答案 1 :(得分:0)
试试这段代码,它对我有用:
$this->load->helper('template'); //You don't need the _helper string, just the name
$var = template_function();
var_dump($var); // or try print_r($var);
尝试修改您的助手:
if ( ! function_exists('tamplate_function') )
{
function tamplate_function()
{
$navigaton_site=array("Header","Sidebar","Body","Footer");
return $navigaton_site;
}
}
如果这不起作用,请尝试使用以下命令获取实例:
$ci = get_instance();
$ci->load->helper('template');