CodeIgniter Forums
WOrking with custom config files - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: WOrking with custom config files (/thread-51616.html)

Pages: 1 2


WOrking with custom config files - El Forum - 05-10-2012

[eluser]xtremer360[/eluser]
I'm trying to figure out why this won't work. I created my own custom config file and autoloaded it and for some reason isn't getting the value of the config index I'm looking for.

I'm getting an error message that says:

Unable to load the requested file: template//cpanel/index.php

So if you notice its missing a value in between two slashes.

Code:
$config['defaultTemplate'] = 'peach';
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dashboard extends CI_Controller {

public function index()
{
  //Config Defaults Start
  $msgBoxMsgs = array();//msgType = dl, info, warn, note, msg
  $cssPageAddons = '';//If you have extra CSS for this view append it here
  $jsPageAddons =  '';//If you have extra JS for this view append it here
  $metaAddons = '';//Sometimes there is a need for additional Meta Data such in the case of Facebook addon's
  $siteTitle = '';//alter only if you need something other than the default for this view.
  //Config Defaults Start
  
  
  //examples of how to use the message box system (css not included).
  //$msgBoxMsgs[] = array('msgType' => 'dl', 'theMsg' => 'This is a Blank Message Box...');
  
  /**********************************************************Your Coding Logic Here, Start*/

  $bodyContent = 'template/'. $this->config->item('defaultTemplate') ."/cpanel/dashboard";//which view file
  $bodyType = "full";//type of template  
  echo $this->config->item('defaultTemplate');
  
  
  

  /***********************************************************Your Coding Logic Here, End*/
  
  //Double checks if any default variables have been changed, Start.
  //If msgBoxMsgs array has anything in it, if so displays it in view, else does nothing.      
  if(count($msgBoxMsgs) !== 0)
  {
   $msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs));
  }
  else
  {
   $msgBoxes = array('display' => 'none');
  }
  
  if($siteTitle == '')
  {
   $siteTitle = $this->metatags->SiteTitle(); //reads
  }
  
  //Double checks if any default variables have been changed, End.

  $this->data['msgBoxes'] = $msgBoxes;
  $this->data['cssPageAddons'] = $cssPageAddons;//if there is any additional CSS to add from above Variable this will send it to the view.
  $this->data['jsPageAddons'] = $jsPageAddons;//if there is any addictional JS to add from the above variable this will send it to the view.
  $this->data['siteTitle'] = $siteTitle;//defaults can be changed via models/metatags.php
     $this->data['bodyType'] = $bodyType;
     $this->data['bodyContent'] = $bodyContent;
  $this->load->view('template/'. $this->config->item('defaultTemplate') .'/cpanel/index', $this->data);
}
    
    function submit()
    {
        
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */



WOrking with custom config files - El Forum - 05-10-2012

[eluser]Aken[/eluser]
To see if the config file is loading, put something like this in it:

Code:
exit('file loaded');

If you receive that message, then the file is being loaded but the value is changing somewhere. If it does not show, then your file isn't being loaded.

If that doesn't help you figure out the problem, post your config file contents, make sure you're autoloading properly, and double check that the variable isn't being overwritten by another config item with the same name (yes, naming conflicts are a common problem).


WOrking with custom config files - El Forum - 05-10-2012

[eluser]weboap[/eluser]
i second @Aken
shortcut to find if naming conflict
test by putting
Code:
$config['defaultTemplate'] = 'peach';

in config.php, if it works then it's just the autoload broke somewhere.


WOrking with custom config files - El Forum - 05-10-2012

[eluser]xtremer360[/eluser]
Yes I put that inside of config.php and it worked so why woudl it be that its not getting that in the myconfig file.

Autoload:

$autoload['config'] = array('myconfig');


WOrking with custom config files - El Forum - 05-10-2012

[eluser]Samus[/eluser]
this "template//cpanel/index.php" makes it look like you didn't specify the config file properly.

post your auto load code here


WOrking with custom config files - El Forum - 05-11-2012

[eluser]xtremer360[/eluser]
See the post above that's my autoload code


WOrking with custom config files - El Forum - 05-11-2012

[eluser]weboap[/eluser]
@xtremer360
you made me doubt my self hehehe.
created a setup.php config file putted it in application/config/setup.php

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

$config['defaultTemplate'] = 'peach';



in application/config/autoload.php

Code:
$autoload['config'] = array('setup');



then in the welcome controller

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



class Welcome extends CI_Controller {
  
function __construct()
{
      parent::__construct();
  
}

public function index()
{
  
   echo $this->config->item('defaultTemplate');
                   die();
}



}



output : peach



it worked.
so either your not autoloading, do to some modification in the lib, or the file is not in the right place or misspelling of the config file name.....
or
the index defaultTemplate is used somewhere with and empty value, set after your autoload. (try to load manually the config right before the line where you need it : $this->config->load('filename'); then if needed change the index to something else ....)


.....



WOrking with custom config files - El Forum - 05-11-2012

[eluser]xtremer360[/eluser]
Its weird because i changed the file name to config1 and changed it to that in the autolaod and then it worked so i just find it odd.


WOrking with custom config files - El Forum - 05-11-2012

[eluser]xtremer360[/eluser]
However I want to do an if statement inside the config file so that if that directory doesn't exist then it defaults to a certain one. So how woudl I check to see if a template exists.

Code:
if () {
    
}
else{
    $config['defaultTemplate'] = 'peach';    
}



WOrking with custom config files - El Forum - 05-11-2012

[eluser]weboap[/eluser]
i will use rather a MY_Controller and extend all the controllers to it, and run in the construct functions that will load the template stuff. read the config, load the template file and that's where i will check if the directory, or the file of the template exist

http://ellislab.com/codeigniter/user-guide/helpers/file_helper.html
http://php.net/manual/en/function.file-exists.php