在我的Codeigniter自定义助手上,我希望能够通过我的load_controller函数传递数据$ params
但我无法通过load_controller('controller', 'function', $setting);
自定义助手
<?php
if (!function_exists('load_controller'))
{
function load_controller($controller, $method = 'index', $params = '')
{
require_once(APPPATH . 'controllers/' . $controller . '.php');
$controller = new $controller();
return $controller->$method();
}
}
我希望能够做到以下这样的事情
<?php
class Column_left extends CI_Controller {
public function index() {
$data['modules'] = array();
$setting = array('width' => '100', 'height' => '100');
$data['modules'][] = load_controller('Slideshow', 'index', $setting);
return $this->load->view('column_left_view', $data, true);
}
}
然后在幻灯片控制器上可以获得宽度或高度
<?php
class Slideshow extends CI_Controller {
public function index($setting) {
echo $setting['width'];
return $this->load->view('slideshow_view', null, true);
}
}
问题如何让我的帮助者能够通过函数传递数据
答案 0 :(得分:1)
您是否需要将数据$setting
传递给控制器?
试试这个:
function load_controller($controller, $method = 'index', $params = ''){
require_once(APPPATH . 'controllers/' . $controller . '.php');
$controller = new $controller();
return $controller->$method($params); //<-- here we are passing the $setting info
}
}
答案 1 :(得分:0)
您可以从该函数返回一个数组。
对于Ex:
function your_helper_function(){
$variable1 = 10;
$variable2 = 20;
$dataArray = array($aVariable, $aVariable2);
return $dataArray;
}