Questions & Answers

Proper controller structure


public function show_sku() {

    public function retrieve_data() {
        $data['product'] = $this->sku->find_sku();
        $this->load->view('check_sku', $data);


$route['check_sku/show_sku'] = 'check_sku/show_sku';
$route['check_sku/retrieve_data'] = 'check_sku/retrieve_data';


<?php echo form_open('/check_sku/retrieve_data'); ?>

<div class="form-group">
    <?php echo form_label('SKU', 'sku', ''); ?>
    <?php echo form_input('sku', '', $options['sku']); ?>
    <?php echo form_submit('', 'Check', 'class="btn btn-primary"') ?>
<?php echo form_close(); ?>


public function find_sku() {
        $sku = $this->input->post('sku');
        $get_data = $this->get_api->get_data("GET", "" . $sku, false);
        $response = json_decode($get_data, true);
        return $response['result'][0]['artikli'][0];

What is the proper way to structure your controller so I don't load the views two times and I don't submit the form by just hitting the route, and so that I pass the data to the view when the form is submitted by clicking the submit.

2023-01-11 09:00:14
how does your model's sky->find_sku function look like? Are you using the input field sku value for a query?
2023-01-11 09:00:14
I fetch some data using the input field value. I posted the model.
Answers(0) :