CodeIgniter Forums
Hide Button on Codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Best Practices (https://forum.codeigniter.com/forum-12.html)
+--- Thread: Hide Button on Codeigniter (/thread-68479.html)



Hide Button on Codeigniter - sanditheresia - 07-17-2017

I am beginner of codeigniter

I want to hide this button action when status is completed

[Image: 28259300-c8aeb2f0-6aff-11e7-8c34-ca07e15dc3c7.png]

this is my code on admin order

Code:
<div class="btn-wrapper pull-left">
                                                <a target="__blank" href="<?php echo $burl.'/print_delivery?id='.$value['order_id']; ?>" class="btn btn-success md-trigger">
                                                    <i class="fa fa-print"></i> Print
                                                </a>
                                            </div>

and this is my controller

Code:
public function print_delivery()
    {
        $id_order = $this->input->get('id');

        $this->load->model('Order');
        $this->Order->updatePrintStatus($id_order);

please help me


RE: Hide Button on Codeigniter - Wouter60 - 07-17-2017

In your view:

Code:
<?php if ($order->status != 'Completed' ) : ?>

//put your existing code for showing the button here; as result of the if .. endif the button will only show up if the order status is not 'Completed'

<?php endif; ?>

The $order->status variable is just my guess. Rename it to what you are using to determine the Order Status.


RE: Hide Button on Codeigniter - sanditheresia - 07-17-2017

like this

Code:
<?php if ($order->status != 'Completed' ) : ?>

thats not working

btw this is my order status

Quote:$data['order_status'] = ['wc-processing'=>'Processing', 'wc-on-hold'=>'On Hold', 'wc-completed'=>'Completed', 'wc-pending'=>'Pending'];



RE: Hide Button on Codeigniter - ivantcholakov - 07-17-2017

I tend not to hide such buttons, but to disable them. The table geometry stays the same, visually this is better IMO.


RE: Hide Button on Codeigniter - Wouter60 - 07-17-2017

(07-17-2017, 06:12 AM)sanditheresia Wrote: btw this is my order status

$data['order_status'] = ['wc-processing'=>'Processing', 'wc-on-hold'=>'On Hold', 'wc-completed'=>'Completed', 'wc-pending'=>'Pending'];

You are passing that from the controller to the view, aren't you?
It's an array of possible order statuses, right?
The table with orders is built up by a foreach {} loop, I guess.
In every iteration you should check the order status of the current record.
If that is 'Completed', don't show the button or disable it.


RE: Hide Button on Codeigniter - my_RZ - 07-17-2017

@sanditheresia

please provide us with full code of your view file..


RE: Hide Button on Codeigniter - sanditheresia - 07-17-2017

(07-17-2017, 08:24 AM)my_RZ Wrote: @sanditheresia

please provide us with full code of your view file..

this is code from my Admin.php controller

Code:
$this->load->model('Order');
        $jumlah_data     = $this->Order->getTotalOrders($filter_data);
        $results         = $this->Order->getOrders($filter_data);
        
        $this->load->library('pagination');

        $config['base_url']        = $data['burl'].'/order?'.$url;
        $config['total_rows']    = $jumlah_data;
        $config['per_page']        = $limit;
        $config['uri_segment']    = $page;

        $this->pagination->initialize($config);        
        $data['pagination'] = $this->pagination->create_links();

        $data['data_order']             = $results;

        $data['filter_id_order']         = $filter_id_order;
        $data['filter_order_date']         = $filter_order_date;
        $data['filter_order_status']     = $order_status;

        $data['order_status'] = ['wc-processing'=>'Processing', 'wc-on-hold'=>'On Hold', 'wc-completed'=>'Completed', 'wc-pending'=>'Pending'];

        $this->load->view('header', $data);
        $this->load->view('order', $data);
        $this->load->view('footer', $data);
    }
        
    public function print_delivery()
    {
        $id_order = $this->input->get('id');

        $this->load->model('Order');
        $this->Order->updatePrintStatus($id_order);

and this is one Order.php from my controller

Code:
function updatePrintStatus($id_order)
    {
        $data = ['printing_status' => 1];

        $this->db->where('ID', $id_order);
        $this->db->update('wpt8_posts', $data);
    }

    function orderPending()
    {
        $sql = "select ID from wpt8_posts as p where
        p.post_status = 'wc-processing' and printing_status = 1";

        $query = $this->db->query($sql);
        return $query->result_array();
    }

    function updateResi($id_order, $tracking_number)
    {
        $data = [
            'tracking_number' => $tracking_number,
            'post_status'      => 'wc-completed'
        ];

        $this->db->where('ID', $id_order);
        $this->db->update('wpt8_posts', $data);
    }
}
?>

and this is from view

Code:
<div class="btn-wrapper pull-left">
<?php if($value['order_status'] == 'wc-processing'){?>
  <a target="__blank" href="<?php echo $burl.'/print_delivery
    id='.$value['order_id']; ?>" class="btn btn-success md-trigger">
  <i class="fa fa-print"></i> Print
  </a>
<?php } ?>



RE: Hide Button on Codeigniter - my_RZ - 07-17-2017

(07-17-2017, 08:37 AM)sanditheresia Wrote:
(07-17-2017, 08:24 AM)my_RZ Wrote: @sanditheresia

please provide us with full code of your view file..

this is code from my Admin.php controller

Code:
$this->load->model('Order');
        $jumlah_data     = $this->Order->getTotalOrders($filter_data);
        $results         = $this->Order->getOrders($filter_data);
        
        $this->load->library('pagination');

        $config['base_url']        = $data['burl'].'/order?'.$url;
        $config['total_rows']    = $jumlah_data;
        $config['per_page']        = $limit;
        $config['uri_segment']    = $page;

        $this->pagination->initialize($config);        
        $data['pagination'] = $this->pagination->create_links();

        $data['data_order']             = $results;

        $data['filter_id_order']         = $filter_id_order;
        $data['filter_order_date']         = $filter_order_date;
        $data['filter_order_status']     = $order_status;

        $data['order_status'] = ['wc-processing'=>'Processing', 'wc-on-hold'=>'On Hold', 'wc-completed'=>'Completed', 'wc-pending'=>'Pending'];

        $this->load->view('header', $data);
        $this->load->view('order', $data);
        $this->load->view('footer', $data);
    }
        
    public function print_delivery()
    {
        $id_order = $this->input->get('id');

        $this->load->model('Order');
        $this->Order->updatePrintStatus($id_order);

and this is one Order.php from my controller

Code:
function updatePrintStatus($id_order)
    {
        $data = ['printing_status' => 1];

        $this->db->where('ID', $id_order);
        $this->db->update('wpt8_posts', $data);
    }

    function orderPending()
    {
        $sql = "select ID from wpt8_posts as p where
        p.post_status = 'wc-processing' and printing_status = 1";

        $query = $this->db->query($sql);
        return $query->result_array();
    }

    function updateResi($id_order, $tracking_number)
    {
        $data = [
            'tracking_number' => $tracking_number,
            'post_status'      => 'wc-completed'
        ];

        $this->db->where('ID', $id_order);
        $this->db->update('wpt8_posts', $data);
    }
}
?>

and this is from view

Code:
<div class="btn-wrapper pull-left">
<?php if($value['order_status'] == 'wc-processing'){?>
  <a target="__blank" href="<?php echo $burl.'/print_delivery
    id='.$value['order_id']; ?>" class="btn btn-success md-trigger">
  <i class="fa fa-print"></i> Print
  </a>
<?php } ?>
Code:
<div class="btn-wrapper pull-left">
<?php if($value['order_status'] == 'wc-completed'){?>
<!---JUST BLANK-->
<?php } ?>



RE: Hide Button on Codeigniter - Wouter60 - 07-17-2017

Why not

Code:
<?php if (.....) : ?>

<?php endif; ?>
This is the so-called alternative php syntax for views.
Much better readable, isn't it?
More info: https://www.codeigniter.com/userguide3/general/alternative_php.html


RE: Hide Button on Codeigniter - my_RZ - 07-17-2017

(07-17-2017, 09:27 AM)Wouter60 Wrote: Why not

Code:
<?php if (.....) : ?>

<?php endif; ?>
This is the so-called alternative php syntax for views.
Much better readable, isn't it?
More info: https://www.codeigniter.com/userguide3/general/alternative_php.html

I agree with you..