My config item is not working correctly, for some reason. Won't display correct theme. It shows the default theme but should display the codeigniter theme.

The default theme is back up so if file not exist it shows default.

I also am getting an array error

1: Should display current theme.

Config file template.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// Template Change
$config['config_template'] = 'codeigniter';
?>

Controller Welcome.php

public function index() {
    $data['header'] = $this->load->view($this->config->item('config_template') . '/template/common/header', NULL, TRUE);
    $data['footer'] = $this->load->view($this->config->item('config_template') . '/template/common/footer', NULL, TRUE);

    if (file_exists(APPPATH . $this->config->item('config_template') . '/template/common/welcome_message', $data)) {
       $this->config->item('config_template') . '/template/common/welcome_message';
    } else {
    $this->load->view('default/template/common/welcome_message', $data);
}

2: Issue with file exists

A PHP Error was encountered Severity: Warning Message: file_exists() expects exactly 1 parameter, 2 given Filename: controllers/welcome.php Line Number: 9

有帮助吗?

解决方案

I've no idea what you're using for the themes, but from what I see:

  • $this->config->item('config_template') . '/template/common/welcome_message';

This line makes absolutely no sense. It's the same if you just write

'something/template/common/welcome_message';

I'm pretty sure you want to do this instead:

$this->load->view($this->config->item('config_template') .'/template/common/welcome_message', $data);
  • file_exists(APPPATH . $this->config->item('config_template') . '/template/common/welcome_message', $data)

Here you have 1 redundant parameter. As the error says, file_exists() accepts 1 argument, and you have 2 (the second is $data) - remove it and the error should go away. I guess you wanted to put it in the next line inside $this->load->view

Edit: And to be clear, here's the complete code you should use.

public function index() {
    $data['header'] = $this->load->view($this->config->item('config_template') . '/template/common/header', NULL, TRUE);
    $data['footer'] = $this->load->view($this->config->item('config_template') . '/template/common/footer', NULL, TRUE);

    if (file_exists(APPPATH . $this->config->item('config_template') . '/template/common/welcome_message')) {
       $this->load->view($this->config->item('config_template') . '/template/common/welcome_message', $data);
    } else {
        $this->load->view('default/template/common/welcome_message', $data);
    }
}

其他提示

You need to load the "template.php", something like this $this->config->load('template');

So your code (Controller Welcome.php) will be:

public function index() {
    $this->config->load('template');
    $data['header'] = $this->load->view($this->config->item('config_template') . '/template/common/header', NULL, TRUE);
    $data['footer'] = $this->load->view($this->config->item('config_template') . '/template/common/footer', NULL, TRUE);

    if (file_exists(APPPATH . $this->config->item('config_template') . '/template/common/welcome_message', $data)) {
       $this->config->item('config_template') . '/template/common/welcome_message';
    } else {
       $this->load->view('default/template/common/welcome_message', $data);
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top