Welcome Guest, Not a member yet? Register   Sign In
Hide Button on Codeigniter
#1
Photo 

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
Reply
#2

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.
Reply
#3

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'];
Reply
#4

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

(07-17-2017, 05: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.
Reply
#6

@sanditheresia

please provide us with full code of your view file..
Reply
#7

(07-17-2017, 07: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 } ?>
Reply
#8

(07-17-2017, 07:37 AM)sanditheresia Wrote:
(07-17-2017, 07: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 } ?>
Reply
#9

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/g...e_php.html
Reply
#10

(07-17-2017, 08: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/g...e_php.html

I agree with you..
Reply




Theme © iAndrew 2016 - Forum software by © MyBB