Welcome Guest, Not a member yet? Register   Sign In
[Solved] Button not changing correct after module installed
#1

(This post was last modified: 09-08-2015, 07:26 PM by wolfgang1983.)

I am creating a module install controller. I am having issue with my view, when I click install button then install the module it should change to the button to modify, or some reason even though module installed button still says install.

How can I make sure that is module is installed then button will say modify and then if module not installed then will say install

As you can see in my image that I attached in the var dump it's showing slideshow installed into database there for button should now be modify but still says install.

View

PHP Code:
<div class="container-fluid">
<
div class="row">
<
div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<
div class="page-header">
<
h1>Modules</h1>
</
div>
</
div>
</
div>
<
div class="row">
<
div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<
div class="table-responsive">
<
table class="table table-bordered table-hover">
<
tbody>
<?
php if ($extensions) { ?>

<?php foreach ($extensions as $extension) { ?>
<tr>

<td><?php echo $extension['name']; ?></td>

<td class="text-right">
<?php if ($extension['installed']) { ?>
<a href="<?php echo $extension['modify']; ?>" class="btn btn-primary">Modify</a>
<?php } else {?>
<a href="<?php echo $extension['install']; ?>" class="btn btn-success">Install</a>
<?php ?>
</td>

</tr>
<?php }?>

<?php ?>

</tbody>
</table>
</div>
</div>
</div>
</div> 


Controller

PHP Code:
<?php

defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Module extends CI_Controller {

    public function 
__construct() {
        
parent::__construct();
        
$this->load->model('extension/model_extension');
        
$this->load->model('extension/model_module');
    }

    public function 
install() {
        
$this->model_extension->install('module'$this->uri->segment(4));

        
redirect('extension/module');
    }

    public function 
index() {
        
$data['extensions'] = array();

        
$extensions $this->model_extension->get_installed('module');

        
var_dump($extensions);

        
$files glob('controllers/modules/*.php');

        if (
$files) {
            foreach (
$files as $file) {
                
                
$extension basename($file'.php');

                
$this->lang->load('module/'$extension'english');
                
                
$data['extensions'][] = array(
                    
'name' => $this->lang->line('heading_title'),
                    
'install' => site_url('extension/module/install' .'/'strtolower($extension)),
                    
'installed' => in_array($extension$extensions),
                    
'modify' => site_url('module/' $extension)
                );
            }
        }

        
$this->load->view('template/common/header_view');
        
$this->load->view('template/extension/module_view'$data);
        
$this->load->view('template/common/footer_view');
    }


Model


PHP Code:
<?php

defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Model_extension extends CI_Model {

    public function 
get_installed($type) {
        
$extension_data = array();

        
$this->db->select('*');
        
$this->db->from($this->db->dbprefix 'extension');
        
$this->db->where('type'$type);
        
$this->db->order_by('code');
        
$query $this->db->get();

        foreach (
$query->result_array() as $result) {
            
$extension_data[] = $result['code'];
        }

        return 
$extension_data;
    }

    public function 
install($type$code) {
        
$data = array(
            
'type' => $type,
            
'code' => $code
        
);

        
$this->db->set($data);
        
$this->db->insert('extension');
    }

    public function 
uninstall($type$code) {
        
$this->db->where('type'$type);
        
$this->db->where('code'$code);
        
$this->db->delete($this->db->dbprefix 'extension');
    }



Attached Files Thumbnail(s)
   

.php   Module.php (Size: 1.25 KB / Downloads: 61)
.php   module_view.php (Size: 827 bytes / Downloads: 53)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

I have solved my problem

Used this $extension = preg_replace('/\\.[^.\\s]{3,4}$/', '',  basename($file));
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB