waktu tersisa untuk klaim DISKON 40% dalam program Full Stack Membership. Klaim Promo!

pegination tidak muncul dan alert juga tidak muncul

Ditanyakan pada tanggal 29 June 2020 oleh Chairrizal Edit  Hapus  Buka Kembali  Tandai 
mohon bantuannya untuk pegination dan alert tidak muncul

untuk penambahan di Db bisa bertambah....mohon bantuannya kak
Comment ..

Coba sertakan errornya (gambar atau contoh kodingan kamu di GDrive). Biar mudah membantunya ^^

Dikomentari pada tanggal 29 June 2020 oleh Yusuf Fazeri Edit  Remove 
Comment ..
Dikomentari pada tanggal 30 June 2020 oleh Chairrizal Edit  Remove 
Comment ..

Request access GDrive coba di accept

Dikomentari pada tanggal 30 June 2020 oleh Yusuf Fazeri Edit  Remove 
Comment ..

access di buka

Dikomentari pada tanggal 30 June 2020 oleh Chairrizal Edit  Remove 

1 JAWABAN / 6 KOMENTAR

User avatar
Ahmad Oriza menjawab pada tanggal 1 July 2020 Jadikan Jawaban Terbaik  Edit  Hapus  Ubah ke Komentar 

Kami perhatikan ada beberapa kesalaham dalam kodenya. Coba dibandingkan lagi dengan kode asli

Controller Category

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Category extends MY_Controller {

    public function __construct()
    {
        parent::__construct();
        $role = $this->session->userdata('role');
        if ($role != 'admin') {
            redirect(base_url('/'));
            return;
        }
    }

    public function index($page = null)
    {
        $data['title']      = 'Admin: Category';
        $data['content']    = $this->category->paginate($page)->get();
        $data['total_rows'] = $this->category->count();
        $data['pagination'] = $this->category->makePagination(
            base_url('category'), 2, $data['total_rows']
        );
        $data['page']       = 'pages/category/index';

        $this->view($data);
    }

    public function search($page = null)
    {
        if (isset($_POST['keyword'])) {
            $this->session->set_userdata('keyword', $this->input->post('keyword'));
        } else {
            redirect(base_url('category'));
        }

        $keyword    = $this->session->userdata('keyword');
        $data['title']      = 'Admin: Category';
        $data['content']    = $this->category->like('title', $keyword)->paginate($page)->get();
        $data['total_rows'] = $this->category->like('title', $keyword)->count();
        $data['pagination'] = $this->category->makePagination(
            base_url('category/search'), 3, $data['total_rows']
        );
        $data['page']       = 'pages/category/index';

        $this->view($data);
    }

    public function reset()
    {
        $this->session->unset_userdata('keyword');
        redirect(base_url('category'));
    }

    public function create()
    {
        if (!$_POST) {
            $input  = (object) $this->category->getDefaultValues();
        } else {
            $input  = (object) $this->input->post(null, true);
        }

        if (!$this->category->validate()) {
            $data['title']          = 'Tambah Kategori';
            $data['input']          = $input;
            $data['form_action']    = base_url('category/create');
            $data['page']           = 'pages/category/form';

            $this->view($data);
            return;
        }

        if ($this->category->create($input)) {
            $this->session->set_flashdata('success', 'Data berhasil disimpan!');
        } else {
            $this->session->set_flashdata('error', 'Oops! Terjadi suatu kesalahan');
        }

        redirect(base_url('category'));
    }

    public function edit($id)
    {
        $data['content'] = $this->category->where('id', $id)->first();

        if (! $data['content']) {
            $this->session->set_flashdata('warning', 'Maaf! Data tidak ditemukan!');
            redirect(base_url('category'));
        }

        if (!$_POST) {
            $data['input']  = $data['content'];
        } else {
            $data['input']  = (object) $this->input->post(null, true);
        }

        if (!$this->category->validate()) {
            $data['title']          = 'Ubah Kategori';
            $data['form_action']    = base_url("category/edit/$id");
            $data['page']           = 'pages/category/form';

            $this->view($data);
            return;
        }

        if ($this->category->where('id', $id)->update($data['input'])) {
            $this->session->set_flashdata('success', 'Data berhasil diperbaharui!');
        } else {
            $this->session->set_flashdata('error', 'Oops! Terjadi suatu kesalahan.');
        }

        redirect(base_url('category'));
    }

    public function delete($id)
    {
        if (!$_POST) {
            redirect(base_url('category'));
        }

        if (! $this->category->where('id', $id)->first()) {
            $this->session->set_flashdata('warning', 'Maaf! Data tidak ditemukan.');
            redirect(base_url('category'));
        }

        if ($this->category->where('id', $id)->delete()) {
            $this->session->set_flashdata('success', 'Data sudah berhasil dihapus!');
        } else {
            $this->session->set_flashdata('error', 'Oops! Terjadi suatu kesalahan.');
        }

        redirect(base_url('category'));
    }

    public function unique_slug()
    {
        $slug       = $this->input->post('slug');
        $id         = $this->input->post('id');
        $category   = $this->category->where('slug', $slug)->first();

        if ($category) {
            if ($id == $category->id) {
                return true;
            }
            $this->load->library('form_validation');
            $this->form_validation->set_message('unique_slug', '%s sudah digunakan!');
            return false;
        }

        return true;
    }

}

/* End of file Category.php */

Model Category

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Category_model extends MY_Model 
{

    protected $perPage = 5;

    public function getDefaultValues()
    {
        return [
            'id'    => '',
            'slug'  => '',
            'title' => ''
        ];
    }

    public function getValidationRules()
    {
        $validationRules = [
            [
                'field' => 'slug',
                'label' => 'Slug',
                'rules' => 'trim|required|callback_unique_slug'
            ],
            [
                'field' => 'title',
                'label' => 'Kategori',
                'rules' => 'trim|required'
            ],
        ];

        return $validationRules;
    }

}

/* End of file Category_model.php */

View category

<main role="main" class="container">
    <?php $this->load->view('layouts/_alert'); ?>
    <div class="row">
        <div class="col-md-10 mx-auto">
            <div class="card mb-3">
                <div class="card-header">
                    <span>Kategori</span>
                    <a href="<?= base_url('category/create') ?>" class="btn btn-sm btn-secondary">Tambah</a>

                    <div class="float-right">
                        <?= form_open(base_url('category/search'), ['method' => 'POST']) ?>
                            <div class="input-group">
                                <input type="text" name="keyword" class="form-control form-control-sm text-center" placeholder="Cari" value="<?= $this->session->userdata('keyword') ?>">
                                <div class="input-group-append">
                                    <button class="btn btn-info btn-sm" type="submit">
                                        <i class="fas fa-search"></i>
                                    </button>
                                    <a href="<?= base_url('category/reset') ?>" class="btn btn-info btn-sm">
                                        <i class="fas fa-eraser"></i>
                                    </a>
                                </div>
                            </div>
                        <?= form_close() ?>
                    </div>
                </div>
                <div class="card-body">
                    <table class="table">
                        <thead>
                            <tr>
                                <th scope="col">#</th>
                                <th scope="col">Title</th>
                                <th scope="col">Slug</th>
                                <th scope="col"></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $no = 0; foreach ($content as $row) :  $no++;?>
                            <tr>
                                <td><?= $no ?></td>
                                <td><?= $row->title ?></td>
                                <td><?= $row->slug ?></td>
                                <td>
                                    <?= form_open("category/delete/$row->id", ['method' => 'POST']) ?>
                                    <?= form_hidden('id', $row->id) ?>
                                    <a href="<?= base_url("category/edit/$row->id") ?>" class="btn btn-sm">
                                        <i class="fas fa-edit text-info"></i>
                                    </a>
                                    <button class="btn btn-sm" type="submit" onclick="return confirm('Apakah yakin ingin menghapus?')">
                                        <i class="fas fa-trash text-danger"></i>
                                    </button>
                                    <?= form_close() ?>
                                </td>
                            </tr>
                            <?php endforeach ?>
                        </tbody>
                    </table>

                    <nav aria-label="Page navigation example">
                        <?= $pagination ?>
                    </nav>
                </div>
            </div>
        </div>
    </div>
</main>
Comment ..

tetap tidak keluar kak...saya tidak menggunakan custom url...jadi tetap menggunakan index.php.
permasalahnnya paginationnya tetap belom muncul

yang ingin saya tanyakan adalah :
ini yang berasal dari codingan di atas:
$data['pagination'] = $this->category->makePagination(
base_url('category'), 2, $data['total_rows']
);

sedangakan punya saya seperti ini:

$data['pagination'] = $this->category->makePagination(base_url('index.php/category'), 2, $data['total_rows']);

ini gmn kak?...untuk yang angka 2 itu apa dan bagai mana penjelasannya?

Dikomentari pada tanggal 1 July 2020 oleh Chairrizal Edit  Remove 
Comment ..

finally done setelah di otak atik...!!! hahahahaha

Dikomentari pada tanggal 4 July 2020 oleh Chairrizal Edit  Remove