GET will not be transmitted

Asked by At

I have a problem with this GET. I want to pass on three values (ygo, dane, 1) with a link to index, so that these values are entered in the respective WHERE. But unfortunately there is no value on the page and I just don't know why.

IMG: https://screenshots.firefox.com/g6qcToRn.../127.0.0.1

Controller:

public function index($slug) {
    $url = 'edition/index';
    $array = explode ('/',$url);
    $data['array'] = $array[0];
    $data['title'] = 'Edition Liste';
    $data['edition_listes'] = $this->Edition_model->edition_listess($slug);
    $this->load->view('templates/header', $data);
    $this->load->view($url, $data);
    $this->load->view('templates/footer');
}
public function edition($tcg,$id,$short) {
    $url = 'edition/edition';
    $array = explode ('/',$url);
    $data['array'] = $array[0];
    $data['get_edition'] = $this->Edition_model->get_edition($tcg,$id,$short);
    $this->load->view('templates/header', $data);
    $this->load->view($url, $data);
    $this->load->view('templates/footer');
} 

Model:

public function edition_listess($slug) {
    $this->db->select('*');
    $this->db->from('db_edition');
    $this->db->where('db_edition.tb_edition_tcg', $slug);
    $this->db->order_by('db_edition.tb_edition_kurzel', 'ASC');
    $this->db->order_by('db_edition.tb_edition_date', 'ASC');
    $query = $this->db->get();
    return $query->result_array();
}
public function get_edition($tcg,$id,$short) {
    $this->db->select('*');
    $this->db->from('db_edition');
    $this->db->where('db_edition.tb_edition_tcg', $tcg);
    $this->db->where('db_edition.tb_edition_id', $id);
    $this->db->or_where('db_edition.tb_edition_kurzel', $short);
    $this->db->order_by('db_edition.tb_edition_kurzel', 'ASC');
    $this->db->order_by('db_edition.tb_edition_date', 'ASC');
    $query = $this->db->get();
    return $query->result_array();
} 

index.php

<?php echo validation_errors(); ?>
<title><?php echo $title; ?></title>

<div class="row">
    <div class="col-xs-6 col-lg-1">
    </div>
    <div class="col-xs-6 col-lg-10">
    <?php foreach ($edition_listes as $edition_liste): ?>
        <div class="list-group">
            <a href="<?php echo base_url(); ?>edition/edition/<?php echo $edition_liste['tb_edition_tcg'];?>/<?php if($edition_liste['tb_edition_kurzel'] > '') { echo $edition_liste['tb_edition_kurzel']; } else { echo $edition_liste['tb_edition_id']; } ?>" class="list-group-item list-group-item-action list-group-item-secondary">
                <div class="media">
                    <img class="media-object img-rounded img-responsive"  src="<?php echo base_url(); ?>/assets/images/display.png" alt="placehold.it/350x250">
                    <div class="media-body">
                        <h4 class="list-group-item-heading"><?php echo $edition_liste['tb_edition_name'];?></h4>
                        <p class="list-group-item-text">
                            <b>SET ID: </b><?php if($edition_liste['tb_edition_kurzel']): echo $edition_liste['tb_edition_kurzel']; endif; ?></br>
                            <b>Kartenmenge: </b><?php echo $edition_liste['tb_edition_size'];?></br>
                            <b>Release: </b>00.00.0000
                        </p>
                    </div>
                    <div class="col-md-3 text-right">
                        <h5 class="colors">Pre-Release: <button class="btn btn-primary"><i class="fa fa-check-square"></i></button></h5>
                        <h5 class="colors">Pre-Release: <button class="btn btn-primary"><i class="fa fa-square"></i></button></h5>
                    </div>
                </div>
            </a>
        </div>
    <?php endforeach; ?>
    </div>
    <div class="col-xs-6 col-lg-1">
    </div>
</div>

edition.php (test page)

<?php echo validation_errors(); ?>
<?php echo $slug; ?>

1 Answers

0
DFriend On

It looks like you are not passing the third argument to edition($tcg,$id,$short). That likely means your model is using null for the value of $short in the call to $this->db->or_where('db_edition.tb_edition_kurzel', $short); so it is probably not returning any records.

Your code could be a lot easier to read. Here is code-snippet suggestion on how to create the link to the edition controller

...
<div class="list-group">
    <?php
    $tcg = $edition_liste['tb_edition_tcg'];

    if($edition_liste['tb_edition_kurzel'] !== '') // use a more reliable test for an empty string than > ''
    {
        $id = $edition_liste['tb_edition_kurzel'];
    }
    else
    {
        $id = $edition_liste['tb_edition_id'];
    }

    $short = 1;
    ?>
    <a href="<?= base_url("edition/edition/$tcg/$id/$short"); ?>" class="list-group-item list-group-item-action list-group-item-secondary">
...

In case you are not familiar with the syntax <?= is exactly the same as <?php echo - but with a lot less typing.

Now, a bonus suggestion. I'm not sure exactly why you are using this code

$url = 'edition/index';

There is a way to get the current controller and method without hard-coding it.

$url = $this->router->class . '/' . $this->router->method;

That way if you rename the controller or the method you don't have to change the hard-coded string. Yeah!

CodeIgniter does not document the router class, but the source code is in /system/core/Router.php and every controller will have an instance of the router class available as the property $this->router.