Welcome Guest, Not a member yet? Register   Sign In
[Solved] Codeigniter form to find theme and update save.
#1

[eluser]riwakawd[/eluser]
Hello. Currently I have in my app/config/setting.php a area where I can change the current theme manually. $config['config_template'] = 'codeigniter';

In my module/settings controller I have got a script that finds and locates themes but can not seem to switch the themes. I am trying to get it so do not have to enter it manually to change the name.

SettingsController.php

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

class Settings extends CI_Controller {

public function index() {
  $data['theme'] = array();
        if ($handle = opendir(FCPATH.APPPATH.'/views/theme')) {
            while (false !== ($entry = readdir($handle))) {
                if ($entry != "." && $entry != ".." && is_dir(FCPATH.APPPATH.'views/theme/'.$entry)) {
                    $data['theme'][$entry] = $entry;
                }
            }
            closedir($handle);
        }
        asort($data['theme']);


  $this->load->view('admin/settings/settings.tpl', $data);
}
}

Settings.view

Code:
<?php echo form_open_multipart('module/settings');?>
<?php echo form_dropdown('theme', $theme, set_value('theme', $theme));?>
<?php echo form_button('Update', 'Update & Save');?>

this is how is displayed on home controller.
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

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

public function index() {

if (file_exists(APPPATH.'views/theme/'.$this->config->item('config_template').'/template/common/home.tpl')) {
        return $this->load->view('theme/'.$this->config->item('config_template').'/template/common/home.tpl', $data);
     } else {
         return $this->load->view('theme/'.'default/template/common/home.tpl', $data);
     }
}
}
#2

[eluser]InsiteFX[/eluser]
Most od the CI directories are read only see the .htaccess files in the directory to see why
#3

[eluser]riwakawd[/eluser]
[quote author="InsiteFX" date="1397994067"]Most od the CI directories are read only see the .htaccess files in the directory to see why
[/quote]

How would you get the theme from folder. In select form.

At the moment I just have to change the name each time want to choose different theme

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

// Set Website Title
$config['getTitle'] = 'Your | Store';

// Template Change
$config['config_template'] = 'codeigniter';

?>

It would be easier if I can just choose from a drop down list from my views/theme

I have a settings.php controller which is in my admin area where function set_theme() is. Just something like opencarts theme selection area.

this is what is in my home.php controller index
Code:
if (file_exists(APPPATH.'views/theme/'.$this->config->item('config_template').'/template/common/home.tpl')) {
        return $this->load->view('theme/'.$this->config->item('config_template').'/template/common/home.tpl', $data);
     } else {
         return $this->load->view('theme/'.'default/template/common/home.tpl', $data);
     }
#4

[eluser]InsiteFX[/eluser]
If you can get the theme name then you can use this to set the name in the config.
Code:
$this->config->set_item('item_name', 'item_value');
#5

[eluser]riwakawd[/eluser]
[quote author="InsiteFX" date="1397999555"]If you can get the theme name then you can use this to set the name in the config.
Code:
$this->config->set_item('item_name', 'item_value');
[/quote]

Where do I use it though.

<select>
<option value="&lt;?php echo $this->config->set_item('views/theme');?&gt;
</select>

I am stuck on this.

#6

[eluser]riwakawd[/eluser]
[quote author="InsiteFX" date="1397999555"]If you can get the theme name then you can use this to set the name in the config.
Code:
$this->config->set_item('item_name', 'item_value');
[/quote]

On My settings.tpl
Code:
<select name="config_template">
&lt;?php if ($template == $config_template) { ?&gt;
<option value="&lt;?php echo $template; ?&gt;" selected="selected">&lt;?php echo $template; ?&gt;</option>
&lt;?php } else { ?&gt;
<option value="&lt;?php echo $template; ?&gt;">&lt;?php echo $template; ?&gt;</option>
&lt;?php } ?&gt;
</select>

Not know what to add to controller yet to be able to find theme.
#7

[eluser]InsiteFX[/eluser]
Take off the FCPATH and just use the APPPATH
#8

[eluser]riwakawd[/eluser]
[quote author="InsiteFX" date="1398013450"]Take off the FCPATH and just use the APPPATH[/quote]

Got code now working but just does not apply the theme. I can see themes in the theme folder but have not any idea now how to make it work with codeigniter so when click save it will change theme

Config file settings.php

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

// Set Website Title
$config['getTitle'] = 'Your | Store';

// Template Change
//$config['config_template'] = 'codeigniter';

?&gt;


Settings Controller

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

class Settings extends CI_Controller {

public function index() {
  if (isset($this->request->post['config_template'])) {
   $this->data['config_template'] = $this->request->post['config_template'];
  } else {
   $this->data['config_template'] = $this->config->item('config_template');
  }

  $this->data['templates'] = array();

  $directories = glob(APPPATH . 'views/theme/*', GLOB_ONLYDIR);

  foreach ($directories as $directory) {
   $this->data['templates'][] = basename($directory);
  }    

  $this->load->view('admin/settings/settings.tpl', $this->data);
}
}

View

Code:
&lt;?php echo form_open('module/settings'); ?&gt;

<select name="config_template">
&lt;?php foreach ($templates as $template) { ?&gt;
&lt;?php if ($template == $config_template) { ?&gt;
<option value="&lt;?php echo $template; ?&gt;" selected="selected">&lt;?php echo $template; ?&gt;</option>
&lt;?php } else { ?&gt;
<option value="&lt;?php echo $template; ?&gt;">&lt;?php echo $template; ?&gt;</option>
&lt;?php } ?&gt;
&lt;?php } ?&gt;
</select>  

&lt;?php echo form_submit('save', 'Save'); ?&gt;

&lt;?php echo form_close(); ?&gt;
#9

[eluser]InsiteFX[/eluser]
Do a redirect and refresh

When I change my themes it's just changing the css file.
#10

[eluser]riwakawd[/eluser]
[quote author="InsiteFX" date="1398075339"]Do a redirect and refresh

When I change my themes it's just changing the css file.
[/quote]

I know how to do it manually. But I am creating admin so users can upload there theme in to theme folder and the got to admin and choose/select there them.




Theme © iAndrew 2016 - Forum software by © MyBB