waktu tersisa untuk klaim Potongan harga Rp 300.000 dalam program Membership. Klaim Promo!

tidak muncul komen di flashdata

Ditanyakan pada tanggal 17 November 2020 oleh Mujahidin Salam Edit  Hapus  Buka Kembali  Tandai 
mohon bantuannya komen di flash data tdk muncul (Berhasil melakukan login!/E-mail atau password salah atau akun anda sedang tidak aktif!) hanya ada kolom berwarna saja .
berikut view login

<main role="main" class="container">
<?php $this->load->view('layouts/_alert') ?>    
    <div class="row">
            <div class="col-md-8 mx-auto">
                <div class="card">
                    <div class="card-header">
                        Formulir Login
                    </div>
                    <div class="card-body">
                        <?=form_open('login', ['method' => 'POST'])?>
                        <div class="form-group">
                                <label for="">E-Mail</label>
                                <!---<input type="email" class="form-control" required>---->
                                <?=form_input(['type' => 'email', 'name' => 'email',
                                'value' => $input->email, 'class'=> 'form-control',
                                'placeholder'=>'Masukkan alamat email ', 'required' =>true])?>
                                <!---<small class="form-text text-danger">E-Mail Harus Diisi</small>---->
                                <?= form_error('email')?>
                            </div>
                            <div class="form-group">
                                <label for="">Password</label>
                                <?= form_password('password', '',['class'=> 'form-control',
                                'placeholder'=>'Masukan password',
                                'required' => true])?>
                                <!---<input type="password" class="form-control" required autofocus>
                                <small class="form-text text-danger">Password Harus Diisi</small>------>
                                <?= form_error('password')?>
                            </div>
                            <button type="submit" class="btn btn-primary">Login</button>
                        <?= form_close()?>
                    </div>
                </div>
            </div>
        </div>
</main>


berikut controller Login
<?php 


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

class Login extends MY_Controller {

    public function __construct()
    {
        parent::__construct();
        $is_login = $this->session->userdata('is_login');

        if ($is_login) {
            redirect(base_url());
            return;
        }
    }
    public function index()
    {
        if (!$_POST){
            $input = (object) $this->login->getDefaultValues();
        } else {
            $input = (object) $this->input->post(null, true);
        }
        if (!$this->login->validate()){
            $data['title'] = 'Login';
            $data['input'] = $input;
            $data['page'] = 'pages/auth/login';

            $this->view($data);
            return;
        }
        if ($this->login->run($input)){
            $this->session->set_flashdata('success', 'Berhasil melakukan login!');
            redirect(base_url());
        } else {
            $this->session->set_flashdata('error', 'E-mail atau password salah atau akun anda sedang tidak aktif!');
            redirect(base_url('login'));
        }
    }
}

/* End of file Login.php */


berikut _alert

<?php 
    $success   = $this->session->flashdata('success');
    $error     = $this->session->flashdata('error');
    $warning   = $this->session->flashdata('warning');

    if ($success) {
        $alert_status = 'alert-success';
        $status       = 'Success!';
        $message      = $success;
    }
    if ($error) {
        $alert_status = 'alert-danger';
        $status       = 'Error!';
        $message      = $error;
    }
    if ($warning) {
        $alert_status = 'alert-warning';
        $status       = 'Warning!';
        $message      = $warning;
    }

?>

<!----tanda = menggantikan php echo----->
<?php if ($success || $error || $warning): ?>
<div class="row">
    <div class="col-md-12">
        <div class="alert <?= $alert_status ?> alert-dismissible fade show" role="alert">
            <strong><? $status?></strong> <? $message?>
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
    </div>
</div>

<?php endif ?>

1 JAWABAN / 0 KOMENTAR

User avatar
Oriza Sahputra menjawab pada tanggal 17 November 2020 Jadikan Jawaban Terbaik  Edit  Hapus  Ubah ke Komentar 
Coba dicocokan dengan ini mas,

View
<main role="main" class="container">
 | 	<?php $this->load->view('layouts/_alert') ?>
 | 	<div class="row">
 | 		<div class="col-md-8 mx-auto">
 | 			<div class="card">
 | 				<div class="card-header">
 | 					Formulir Login
 | 				</div>
 | 				<div class="card-body">
 | 					<?= form_open('login', ['method' => 'POST']) ?>
 | 						<div class="form-group">
 | 							<label for="">E-Mail</label>
 | 							<?= form_input(['type' => 'email', 'name' => 'email', 'value' => $input->email, 'class' => 'form-control', 'placeholder' => 'Masukkan alamat email', 'required' => true]) ?>
 | 							<?= form_error('email') ?>
 | 						</div>
 | 						<div class="form-group">
 | 							<label for="">Password</label>
 | 							<?= form_password('password', '', ['class' => 'form-control', 'placeholder' => 'Masukkan password', 'required' => true]) ?>
 | 							<?= form_error('password') ?>
 | 						</div>
 | 						<button type="submit" class="btn btn-primary">Login</button>
 | 					<?= form_close() ?>
 | 				</div>
 | 			</div>
 | 		</div>
 | 	</div>
 | </main>
Controller
<?php
 | 

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

 | class Login extends MY_Controller 
 | {
 | 

 | 	public function __construct()
 | 	{
 | 		parent::__construct();
 | 		$is_login	= $this->session->userdata('is_login');
 | 

 | 		if ($is_login) {
 | 			redirect(base_url());
 | 			return;
 | 		}
 | 	}
 | 

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

 | 		if (!$this->login->validate()) {
 | 			$data['title']	= 'Login';
 | 			$data['input']	= $input;
 | 			$data['page']	= 'pages/auth/login';
 | 

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

 | 		if ($this->login->run($input)) {
 | 			$this->session->set_flashdata('success', 'Berhasil melakukan login!');
 | 			redirect(base_url());
 | 		} else {
 | 			$this->session->set_flashdata('error', 'E-Mail atau Password salah atau akun Anda sedang tidak aktif!');
 | 			redirect(base_url('login'));
 | 		}
 | 	}
 | 

 | 

 | }
 | 

 | /* End of file Login.php */
Alert
<?php
 | 	$success	= $this->session->flashdata('success');
 | 	$error		= $this->session->flashdata('error');
 | 	$warning	= $this->session->flashdata('warning');
 | 

 | 	if ($success) {
 | 		$alert_status	= 'alert-success';
 | 		$status			= 'Success!';
 | 		$message		= $success;
 | 	}
 | 

 | 	if ($error) {
 | 		$alert_status	= 'alert-danger';
 | 		$status			= 'Error!';
 | 		$message		= $error;
 | 	}
 | 

 | 	if ($warning) {
 | 		$alert_status	= 'alert-warning';
 | 		$status			= 'Warning!';
 | 		$message		= $warning;
 | 	}
 | ?>
 | 

 | <?php if ($success || $error || $warning): ?>
 | <div class="row">
 | 	<div class="col-md-12">
 | 		<div class="alert <?= $alert_status ?> alert-dismissible fade show" role="alert">
 | 			<strong><?= $status ?></strong> <?= $message ?>
 | 			<button type="button" class="close" data-dismiss="alert" aria-label="Close">
 | 				<span aria-hidden="true">&times;</span>
 | 			</button>
 | 		</div>
 | 	</div>
 | </div>
 | <?php endif ?>