i've create a custom admin page for my opencart panel. If I try to run route index.php?route=report/remarketing, system will log out instead of display page!
here's code:
controller
class ControllerReportRemarketing extends Controller {
public function index()
{
$template="report/remarketing.tpl";
$this->load->language('report/remarketing');
$this->load->model('report/remarketing');
$this->template = ''.$template.'';
$this->data['record'] = 'test';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
}
model (have no methods)
class ModelReportRemarketing extends Model {
}
view
<?php echo $header; ?>
<div id="content">
<?php echo $record; ?>
</div>
<?php echo $footer; ?>
Also i've setting access permission to user in User Groups
I think you are using the old version opencart's code, here is the example for opencart version 2.0.2.0:
First, creat 'remarketing.php' under admin\language\english\report, add below content:
<?php
// Heading
$_['heading_title'] = 'Marketing Report';
Second, modify 'remarketing.php' under admin\controller\report as below
<?php
class ControllerReportRemarketing extends Controller{
public function index(){
// displayed text import
$this->load->language('report/remarketing');
// get header and footer
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/feed', 'token=' . $this->session->data['token'], 'SSL')
);
$data['heading_title'] = $this->language->get('heading_title');
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
// the model, need not to import
// $this->load->model('report/remarketing');
// testing
$data['record'] = 'test';
$this->response->setOutput($this->load->view("report/remarketing.tpl", $data));
}
}
?>
Last, modify 'remarketing.tpl' under admin\view\template\report
<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
<div class="page-header">
<div class="container-fluid">
<h1><?php echo $heading_title; ?></h1>
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><?php echo $breadcrumb['text']; ?></li>
<?php } ?>
</ul>
</div>
</div>
<div class="container-fluid"><?php echo $record; ?></div>
</div>
<?php echo $footer; ?>
Related
Here are the changes applied according to #daniel's Answer.
In \catalog\view\theme\default\template\extension\module\sibling_category.tpl
<div class="box box-with-categories">
<div class="box-heading check_2"><?php echo $heading_title; ?></div>
<div class="strip-line"></div>
<div class="box-content box-category">
<ul class="accordion" id="accordion-category">
<?php $i = 0; foreach ($categories as $category) { $i++; ?>
<li class="panel">
<?php if ($category['category_id'] == $category_id) { ?>
<?php echo $category['name']; ?>
<?php } else { ?>
<?php echo $category['name']; ?>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
\catalog\controller\extension\module\sibling_category.php
<!--Have changed the controller logic, like you said -->
And In \catalog\language\en-gb\extension\module\sibling_category.php
<?php
// Heading
$_['heading_title'] = 'Sibling Categories';
So, Now what to do for appearing on list -> inside Category Layout.
And is there any way we can do this in coding so this appear in product/category.tpl file, so we don't need to create all files in admin folder.
EDIT: I've rewritten this answer to make it simpler to follow.
Your best bet here is to create a new Module rather than including this in the template. There are two stages: creating admin files & creating front-end files.
FRONT END
Start by duplicating all the front-end files of the standard "Category" module which consist of the following files, rename them according to your own definition e.g. sibling_category wherever you have category:
\catalog\view\theme\default\template\extension\module\category.tpl
\catalog\controller\extension\module\category.php
\catalog\language\en-gb\extension\module\category.php
We don't need a model here as the model for this as the ModelCatalogCategory class has the desired ability already.
So now you need to change the controller logic, edit the newly created sibling_category.php controller file. What we're doing here is getting the current category data ($current_id & $current_category), extracting the Parent category's id (parent_id) and then getting all children of the parent_id aka "siblings"
<?php
class ControllerExtensionModuleSiblingCategory extends Controller {
public function index() {
$this->load->language('extension/module/category');
$data['heading_title'] = $this->language->get('heading_title');
if (isset($this->request->get['path'])) {
$parts = explode('_', (string)$this->request->get['path']);
} else {
$parts = array();
}
if (isset($parts[0])) {
$data['category_id'] = $parts[0];
} else {
$data['category_id'] = 0;
}
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$current_id = $parts[count($parts) - 1];
$current_category = $this->model_catalog_category->getCategory($current_id);
$siblings = $this->model_catalog_category->getCategories($current_category['parent_id']);
foreach ($siblings as $category) {
$data['sibling_categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] ,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
$data['current_id'] = $current_id;
return $this->load->view('extension/module/sibling_category', $data);
}
}
Here's the default OC template's category.tpl modules file adjusted (edit for your template file accordingly replacing "$category_id" with "$current_id":
<div class="list-group">
<?php foreach ($sibling_categories as $category) { ?>
<?php if ($category['category_id'] == $current_id) { ?>
<?php echo $category['name']; ?>
<?php if ($category['children']) { ?>
<?php foreach ($category['children'] as $child) { ?>
<?php if ($child['category_id'] == $child_id) { ?>
- <?php echo $child['name']; ?>
<?php } else { ?>
- <?php echo $child['name']; ?>
<?php } ?>
<?php } ?>
<?php } ?>
<?php } else { ?>
<?php echo $category['name']; ?>
<?php } ?>
<?php } ?>
</div>
ADMIN AREA
In order to manage the module in the admin area, you will need to duplicate the language file and create a controller and the view:
\admin\language\en-gb\extension\module\category.php
Create a new file in the path \admin\controller\extension\module\sibling_category.php and insert this code:
<?php
class ControllerExtensionModuleSiblingCategory extends Controller {
private $error = array();
public function index() {
$this->load->language('extension/module/sibling_category');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('extension/module');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
if (!isset($this->request->get['module_id'])) {
$this->model_extension_module->addModule('sibling_category', $this->request->post);
} else {
$this->model_extension_module->editModule($this->request->get['module_id'], $this->request->post);
}
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true));
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_disabled'] = $this->language->get('text_disabled');
$data['entry_status'] = $this->language->get('entry_status');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true)
);
if (!isset($this->request->get['module_id'])) {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/html', 'token=' . $this->session->data['token'], true)
);
} else {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/html', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true)
);
}
if (!isset($this->request->get['module_id'])) {
$data['action'] = $this->url->link('extension/module/sibling_category', 'token=' . $this->session->data['token'], true);
} else {
$data['action'] = $this->url->link('extension/module/sibling_category', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true);
}
$data['cancel'] = $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true);
if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
$module_info = $this->model_extension_module->getModule($this->request->get['module_id']);
}
if (isset($this->request->post['name'])) {
$data['name'] = $this->request->post['name'];
} elseif (!empty($module_info)) {
$data['name'] = $module_info['name'];
} else {
$data['name'] = '';
}
if (isset($this->request->post['module_description'])) {
$data['module_description'] = $this->request->post['module_description'];
} elseif (!empty($module_info)) {
$data['module_description'] = $module_info['module_description'];
} else {
$data['module_description'] = array();
}
$this->load->model('localisation/language');
$data['languages'] = $this->model_localisation_language->getLanguages();
if (isset($this->request->post['status'])) {
$data['status'] = $this->request->post['status'];
} elseif (!empty($module_info)) {
$data['status'] = $module_info['status'];
} else {
$data['status'] = '';
}
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('extension/module/sibling_category', $data));
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'extension/module/category')) {
$this->error['warning'] = $this->language->get('error_permission');
}
return !$this->error;
}
}
Finally create the view file at the path \admin\view\template\extension\module\sibling_category.tpl and insert the following:
<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right">
<button type="submit" form="form-category" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
<i class="fa fa-reply"></i></div>
<h1><?php echo $heading_title; ?></h1>
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><?php echo $breadcrumb['text']; ?></li>
<?php } ?>
</ul>
</div>
</div>
<div class="container-fluid">
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<?php } ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_edit; ?></h3>
</div>
<div class="panel-body">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-html" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-status"><?php echo $entry_status; ?></label>
<div class="col-sm-10">
<input type="hidden" name="name" value="<?php echo $heading_title; ?>" id="input-name" class="form-control" />
<select name="status" id="input-status" class="form-control">
<?php if ($status) { ?>
<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
<option value="0"><?php echo $text_disabled; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_enabled; ?></option>
<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
<?php } ?>
</select>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php echo $footer; ?>
Once you've done this, you may need to update your admin permissions. Navigate to "Settings=>Users=>UserGroups" and edit your Admin user type. Make sure you either "Select All" for read and modify permission or select it manually.
You need to then "Install" this module and then edit it, set it to enabled and Save. You'll notice a "Sub-module" listed below the "Sibling Category" this is to get the module in the 'Layouts' page. Do not create multiple instances of the module as it may cause confusion on the layouts - unless you understand what you're doing.
NB When duplicating the language files, remember to find & replace all instances of "Category" with "Sibling Category"
I'm trying to list categories names and images in OpenCart via custom controller and custom template and this code is not working
Controller File catalog\controller\designer\listing.php
class ControllerDesignerListing extends Controller {
public function index(){
$this->document->setTitle("Listign Designers ");
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/designer/listing.tpl')) {
$this->template = $this->config->get('config_template') . '/template/designer/listing.tpl';
} else {
$this->template = 'default/template/designer/listing.tpl';
}
$this->load->model('catalog/category');
$this->data['categories'] = array();
foreach ($this->model_catalog_category->getCategories(array()) as $category) {
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name']
);
}
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
// call the "View" to render the output
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/designer/listing.tpl', $data));
}
}
and that is the template file
<?php if($categories) { ?>
<?php foreach ($categories as $category) { ?>
<div class="col-md-3 col-sm-4 col-xs-6"><!--item-->
<div class="item">
<div class="img-wrap"><img src="imgs/list-image.jpg" alt=""></div>
<div class="content">
<div class="flag"><img src="imgs/flag-place.jpg" alt=""></div><a href="#">
<h4><?php echo $category['name']; ?></h4></a>
<h5>tokyo, japan</h5>FOLLOW
</div>
</div>
</div>
<?php } ?>
<?php } ?>
Here is some silly mistake,
Find $this->data['categories'] in catalog\controller\designer\listing.php and replace with $data['categories']
This will work .
Whenever, you upgrade opencart files from version 1.5.x.x to 2.x.x.x, Always keep this in mind that, this is the major changes which comes in opencart version 2.x.x.x
I think this is basic problem for open cart, but I cant fix it, in view I put 1 field head_text_field then i put to variable in controller then use var_dump for check value
This for View :
<?php echo $header; ?>
<div id="content">
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><?php echo $breadcrumb['text']; ?>
<?php } ?>
</div>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<?php if ($success) { ?>
<div class="success"><?php echo $success; ?></div>
<?php } ?>
<div class="box">
<div class="heading">
<h1><img src="view/image/product.png" alt="" /> <?php echo $heading_title; ?></h1>
<div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><?php echo $button_cancel; ?></div>
</div>
<div class="content">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
<table class="form">
<tr>
<td><span class="required">*</span> <?php echo $entry_head; ?></td>
<td><input type="text" name="head_text_field" value="<?php echo $head_text_field; ?>" placeholder="Input Head Text" size="40"/></td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php echo $footer; ?>
Controller:
<?php
class ControllerItemItem extends Controller {
private $error = array();
public function index() {
$this->language->load('item/item');
$this->document->setTitle($this->language->get('heading_title'));
$this->getList();
}
protected function getList(){
if (isset($this->request->get['head_text_field'])){
$head_text_field = $this->request->get['head_text_field'];
var_dump($head_text_field); exit; // VAR_DUMP HERE
} else {
$head_text_field = null;
echo "FAILED"; // FAILED HERE
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('module/item', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['entry_head'] = $this->language->get('entry_head');
$this->data['button_save'] = $this->language->get('button_save');
$this->data['button_cancel'] = $this->language->get('button_cancel');
$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
$this->data['action'] = $this->url->link('item/item/insert', 'token=' . $this->session->data['token'], 'SSL');
$this->data['token'] = $this->session->data['token'];
$this->template = 'item/item.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
public function insert()
{
var_dump($head_text_field); exit;
}
}
?>
When I try input, result is FAILED?? Where I did mistake? for model I not call or use it right now in controller.
EDIT 1
Sorry i add function insert for make it not error (for button insert in controller bottom)
If you want to get any variable from opencart controller in your view then you need to pass this variable as below:
Controller File
if (isset($this->request->post['head_text_field'])){
$this->data['head_text_field'] = $this->request->get['head_text_field']; // Your variable
var_dump($this->data['head_text_field']); exit; // VAR_DUMP HERE
} else {
$this->data['head_text_field'] = null;
echo "FAILED"; // FAILED HERE
}
Now you can get head_text_field in your view file as $head_text_field.
Edit
public function insert()
{
if (($this->request->server['REQUEST_METHOD'] == 'POST')) {
echo $this->request->post['head_text_field']; // Your field value
}
}
$this->request->post['head_text_field']
I am trying to setup a demo blog and i want every post to have a thumbnail. Look at the blog first: my demo blog. I can create new blog post from here creating new post and successfully show them in the blog. I also have gallery page where i can upload images, look here: gallery page. but i want the new post page to have the image upload option and it should add a single image to every post that i publish from the new post page like so: example. How i can i do that? I have tried so many times but failed to show image with every post.
Model for post:
class Post extends CI_Model
{
function get_posts($num=20, $start=0) {
$this->db->select()->from('posts')->where('active',1)->order_by('date_added', 'desc')->limit(20,0);
$query = $this->db->get();
return $query->result_array();
}
function get_posts_count() {
$this->db->select('postID')->from('posts')->where('active', 1);
$query = $this->db->get();
return $query->num_rows();
}
function get_post($postID) {
$this->db->select()->from('posts')->where(array('active'=>1, 'postID'=> '$postID'))->order_by('date_added', 'desc');
$query = $this->db->get();
return $query->first_row('array');
}
function insert_post($data) {
$this->db->insert('posts', $data);
return $this->db->insert_id();
}
}
Controller for post:
class Posts extends CI_Controller
{
function __construct() {
parent::__construct();
$this->load->model('post');
$this->load->helper('form');
}
function index($start=0) {
$data['posts']=$this->post->get_posts(5, $start);
$this->load->library('pagination');
$config['base_url'] = base_url() . 'posts/index/';
$config['total_rows'] = $this->post->get_posts_count();
$config['per_page'] = 5;
$this->pagination->initialize($config);
$data['pages'] = $this->pagination->create_links();
$this->load->view('header');
$this->load->view('post_index',$data);
$this->load->view('footer');
}
function post($postID) {
$data['post']= $this->post->get_post($postID);
$this->load->view('post',$data);
}
function new_post() {
if ($_POST) {
$data=array(
'title'=> $_POST['title'],
'post' => $_POST['post'],
'active'=> 1
);
$this->post->insert_post($data);
redirect(base_url().'posts/');
} else {
$this->load->view('new_post');
}
}
}
Index page view: where all blog posts are shown:
<?php
if (!isset($posts)) {
?>
<p>there is currently no post in the database</p>
<?php
} else {
foreach ($posts as $row) {
?>
<h2 class="title"><a class="link_title" href="<?php echo base_url()?>posts/post/<?echo $row['postID']?>"><?php echo $row['title']?></a><a class="edit" href="<?php echo base_url()?>posts/editpost/<?echo $row['postID']?>">Edit</a> / <a class="delete" href="<?php echo base_url()?>posts/<?echo $row['postID']?>">Delete</a></h2>
<p><?php echo substr(strip_tags($row['post']),0,200) . ".."?></p>
<p>Read more</p>
<hr>
<?php
}
}
?>
<?php echo $pages; ?>
This is the new post page view where i want the image upload option available:
<form action="<?php echo base_url()?>posts/new_post" method="post">
<p>Title: <input name="title" type="text"></p>
<p>Description: <br><textarea name="post" cols="50" rows="30"></textarea></p>
<p><input type="submit" value="Add Post"></p>
</form>
I have also some codes to upload image to the galley page. I am sharing this if it helps any.
Gallery model:
class Gallery_model extends CI_Model
{
var $gallery_path;
var $gallery_path_url;
function __construct()
{
parent::__construct();
$this->gallery_path = './images';
$this->gallery_path_url = base_url() . 'images/';
}
function do_upload() {
$config = array(
'allowed_types' => 'jpg|png|jpeg',
'upload_path' => $this->gallery_path
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->gallery_path . '/thumbs',
'maintain_ratio' => true,
'width' => 150,
'height' => 75
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
function get_images() {
$files = scandir($this->gallery_path);
$files = array_diff($files, array('.', '..', 'thumbs'));
$images = array();
foreach ($files as $file) {
$images[] = array(
'url' => $this->gallery_path_url . $file,
'thumb_url' => $this->gallery_path_url . 'thumbs/' . $file
);
}
return $images;
}
}
Gallery controller:
class Gallery extends CI_Controller
{
function index() {
$this->load->model('Gallery_model');
if ($this->input->post('upload')) {
$this->Gallery_model->do_upload();
}
$data['images'] = $this->Gallery_model->get_images();
$this->load->view('header');
$this->load->view('gallery', $data);
$this->load->view('footer');
}
}
Gallery view:
<div class="gallery">
<?php if (isset($images) && count($images)):
foreach ($images as $image): ?>
<div class="thumbs">
<a href="<?php echo $image['url']; ?>">
<img src="<?php echo $image['thumb_url']; ?>" alt="">
</a>
</div>
<?php endforeach; else: ?>
<div class="blank_gallery">Please upload some pictures here</div>
<?php endif; ?>
</div>
<div class="upload">
<?php
echo form_open_multipart('gallery');
echo form_upload('userfile');
echo form_submit('upload', 'Upload');
echo form_close();
?>
How can this gallery page codes be used with the new post page page so that every post has a thumbnail .
I am learning php. Don't know know how to figure this out. Please help me.
Maybe i didn't understand your problem, but i can figure that you will need this plugin:
[http://jquery.malsup.com/form][1]
[Example at : http://jquery.malsup.com/form/progress.html][2]
This would help you to upload the pic first then edit/save the article, because your "gallery page" will only save and upload images and you need to link these 2 pages with this ajax image plugin.
I have hit a brick wall on my codeigniter project.
I can update my theme/template to database via select form in my settings. I can do that OK and the themes/templates show up OK in the select form.
But the $templates == $config_template not showing the current theme/template that is selected.
I am not to sure what to add for the controller part and the model to be able to make it display current theme/template from database as first one.
Here is what I have done so far.
Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Settings extends MX_Controller {
public function index() {
$this->document->setTitle($this->lang->line('heading_title'));
$data['action'] = site_url('admin/settings');
$data['logout'] = site_url('admin/logout');
$data['home'] = site_url('admin/dashboard');
$data['cancel'] = site_url('admin/dashboard');
$this->load->model('admin/setting/model_setting_store');
$this->model_setting_store->config_template();
$data['templates'] = array();
$directories = glob(APPPATH . 'modules/catalog/views/theme/*', GLOB_ONLYDIR);
foreach ($directories as $directory) {
$data['templates'][] = basename($directory);
}
$this->load->library('form_validation');
$this->form_validation->set_rules('config_meta_title', 'Website Title');
$this->form_validation->set_rules('config_meta_description', 'Description');
$this->form_validation->set_rules('config_meta_keyword', 'Keywords');
$this->form_validation->set_rules('config_template', 'Template');
if ($this->form_validation->run() == FALSE) {
return $this->load->view('setting/settings', $data);
} else {
redirect('admin/dashboard');
}
}
}
Model
<?php
class Model_setting_store extends CI_Model {
function config_template() {
$data = array(
'setting_id' => "10",
'website_id' => "0",
'group' => "config",
'key' => "config_template",
'value' => $this->input->post('config_template')
);
$this->db->update('setting', $data);
}
}
View
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-setting" class="form-horizontal">
<ul class="nav nav-tabs" role="tablist" id="myTab">
<li class="active"><?php echo $tab_general;?></li>
<li><?php echo $tab_store; ?></li>
<li><?php echo $tab_server; ?></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab-general"></div>
<div class="tab-pane" id="tab-store">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-template"><?php echo $entry_template; ?></label>
<div class="col-sm-10">
<select name="config_template" id="input-template" class="form-control">
<?php foreach ($templates as $template) { ?>
<?php if ($template == $config_template) { ?>
<option value="<?php echo $template; ?>" selected="selected"><?php echo $template; ?></option>
<?php } else { ?>
<option value="<?php echo $template; ?>"><?php echo $template; ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
</form>
Haven't exactly tested it out but you can try this out with set_select using the Form Helper.
<select name="config_template" id="input-template" class="form-control">
<?php foreach( $templates as $template ): ?>
<option value="<?php echo $template; ?>" <?php echo set_select('config_template', $template, $template == $config_template ? TRUE : FALSE); ?>><?php echo $template; ?></option>
<?php endforeach; ?>
</select>
Edit: I actually don't see where you've set $config_template exactly. I only see it referenced in the model as $data['value'] or what would be $value in the view.