Welcome Guest, Not a member yet? Register   Sign In
Defining a Theme
#1

[eluser]xtremer360[/eluser]
I have a few different themes that I'm using for my codeigniter application. What I want to do is define the default theme for my app to use and then work it into my controllers. However I'm getting a Use of undefined constant DEFAULTTHEME - assumed 'DEFAULTTHEME' on both lines that I use the constant in my controller. Any ideas on the fix?

So I developed a themes.php file:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

define('DEFAULTTHEME', 'peach');

And then my controller:
Code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {


public function index()
{
  $message_box_messages = array();
        $css_page_addons = '';
        $js_page_addons =  '[removed][removed]';
        $meta_tag_addons = '';
        $site_title = 'KOW Manager Login';
        
        if ( !$this->session->userdata( 'xtr' ) == 'yes' )
        {
            $body_content = DEFAULTTHEME . 'usermanagement/forms/login_form';
            $body_type = 'full';
        }
        else
        {
            redirect('cpanel');
        }
        
        if ( count( $message_box_messages ) !== 0 )
        {
            $message_boxes = $this->functions_model->build_message_boxes_output( array( 'display' => 'show', 'messages' => $message_box_messages ) );
        }
        else
        {
            $message_boxes = array( 'display' => 'none' );
        }
        
        $meta_tags = $this->functions_model->meta_tags();
        
        if ( isset( $site_title ) && ( empty( $site_title ) ) )
        {
            $site_title = $this->functions_model->site_title();
        }
        
        $this->data = compact( 'message_boxes', 'css_page_addons', 'js_page_addons', 'site_title', 'body_content', 'body_type', 'meta_tags' );
        $this->load->view( DEFAULTTHEME . 'usermanagement/index', $this->data );
}
    }
}
#2

[eluser]CroNiX[/eluser]
And how are you loading/including your themes.php file so that constant gets defined? It looks like you either aren't including it or it's being included somewhere after you are using the constant so it comes up as undefined.

I'd use CI's config class to set that, or define it in index.php, or in constants.php so it will be available to everything because those get loaded before any controllers, etc.
#3

[eluser]xtremer360[/eluser]
Okay so I moved them into the constants file and have this:

Code:
define('THEMESPATH', 'themes');
define('DEFAULTTHEME', 'peach');
define('ASSETSPATH', base_url() . '/assets');

And its telling me that the base_url function is undefined.
#4

[eluser]CroNiX[/eluser]
Yes, when CI loads/includes those files a lot of the rest of CI isn't instantiated yet. They're config files meant to store simple text settings.

You can also always create a helper or a simple library and autoload them to create more advanced/dynamic settings/functions that would be available to your code globally, just like the base_url() you're using from the url helper.




Theme © iAndrew 2016 - Forum software by © MyBB