简体   繁体   中英

Redirect doesn't work after insert batch codeigniter

I have a problem after inserting some data from array, the insert data works properly. But the Redirect doesn't work, I don't understand the error, because no error message show just the blank page, I have tried and tried until it become habit that makes me tired.

Here is the Function Controller that I use:

public function all() {
    $data       = array();
    $idkelas    = $this->input->post('kelas');
    $idabsen    = $this->input->post('idabsensi');
    $idabsen2   = $this->input->post('idabsen');
    $id         = $this->input->post('idsiswa');
    $hadir  = $this->input->post('hadir');
    $smt        = $this->input->post('semester');
    $jamke  = $this->input->post('jamke');

    $count      = count($id);
    // to absensi
    $this->db->query("UPDATE absensi SET jmlhadir = '$count' WHERE idabsensi = '$idabsen2'");

    // to absensidetail
    for($j=0; $j < (int)($count); $j++) {
        $data[] = array(
            'idabsensi'     => $idabsen[$j],
            'idsiswa'       => $id[$j],
            'statusabsen'   => $hadir[$j],
            'semester'      => $smt[$j],
            'jamke'         => $jamke[$j]
            );
        }
        return $this->db->insert_batch('absensidetail', $data);
        redirect('absensi/absen/pilihkelas/'.$idkelas, 'refresh');

}

This is the View:

<form action="<?php echo base_url()?>absensi/absen/all" method="post">
<input type="submit" class="btn btn-info btn-large" value="ABSENT ALL" />
<table class="table table-striped table-bordered table-condensed">
            <thead>
                <tr>
                    <th>No.</th>
                    <th>No. Induk</th>
                    <th>Student Name</th>
                    <th>Gender</th>
                    <th>State</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
            <?php $i=0 ?>
            <?php foreach($kel as $d):
            $i++;
            ?>
            <tr class="list-users">
                <td><input type="hidden" name="idsiswa[]" value="<?=$d->idsiswa?>" readonly><?=$d->idsiswa?></td>
                <td><input type="hidden" name="hadir[]" value="hadir" readonly><input type="hidden" name="jamke[]" value="<?=$jamke?>" readonly><input type="hidden" name="mapel" value="<?=$idmapel?>" readonly><?=$d->noinduk?></td>
                <td><input type="hidden" name="kelas" value="<?=$d->kelas?>" readonly><input type="hidden" name="semester[]" value="<?=$h_getsmt->idsemester?>" readonly><?=$d->namasiswa?></td>
                <td><input type="hidden" name="idabsensi[]" value="<?=$d->idabsensi?>" readonly><input type="hidden" name="idabsen" value="<?=$d->idabsensi?>" readonly><?=$d->jeniskelamin?></td><td><span class="label label-unabsent">unabsent</span></td>
                <td>
                    <div class="btn-group">
                        <a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#">Actions <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a ><i class="icon-pencil"></i>Press Button<BR>ABSENT ALL First</a></li>
                        </ul>
                    </div>
                </td></tr>
            <?php endforeach ?>
            </tbody>
        </table>
     </form>

I really hope someone can help me. Thank You

The redirect would need to come before return

This is from php.net :

If called from within a function, the return statement immediately ends execution of the current function, and returns its argument as the value of the function call. return also ends the execution of an eval() statement or script file.

You can also check out: How to make a redirect in PHP?

Remove return from the statement for batch insert. If there is return , it will not go to the next statement written for redirection.

Update it like this.

$this->db->insert_batch('absensidetail', $data);
redirect('absensi/absen/pilihkelas/'.$idkelas, 'refresh');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM