-1
我使用php function_exists()函数存在于我的欢迎控制器上。但由于某种原因,即使我的幻灯片放映功能存在,它仍然会抛出我的show_error。Codeigniter function_exists无法正常工作
随着我的foreach循环,我从数据库中获取模块函数名,其在foreach循环中被称为$function = $module['code'];
的问题是:我怎么能确保function_exists检查 功能正常存在?
<?php
class Welcome extends CI_Controller {
public function index() {
$data['content_top'] = $this->content_top();
$this->load->view('home', $data);
}
public function content_top() {
$data['modules'] = array();
$modules = $this->get_module();
foreach ($modules as $module) {
$function = $module['code'];
if (function_exists($function)) {
$setting_info = array('test' => 'testing');
if ($setting_info) {
$data['modules'][] = $this->$function($setting_info);
}
} else {
show_error('This ' . $function . ' does not exist on ' . __CLASS__ . ' controller!');
}
}
return $this->load->view('content_top', $data, TRUE);
}
public function banner() {
}
public function slideshow($setting) {
$data['test'] = $setting['test'];
$this->load->view('module/slideshow', $data);
}
public function get_module() {
$query = $this->db->get('modules');
return $query->result_array();
}
}
任何人都可以问为什么投票的理由会很高,知道这样可以提高。 – user4419336