如何使用CodeIgniter 3中的引导程序警报组件显示错误警报

a11xaf1n  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(159)

我正在创建上传,编辑和删除在Codeigniter,我希望引导警报应该显示上传错误(如果有的话)在div警报。代码的控制器如下所述,请协助。
控制器代码从此处开始

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

/**
 * 
 */
class Admin_Controller extends CI_Controller
{
    
    function __construct()
    {
        parent::__construct();
        $this->load->library("session");
    }

    public function registerAdminDetails()
    {
        $config['upload_path'] = 'assets/img/uploads/reg_Admin/';
        $config['allowed_types'] = 'jpg|jpeg|png';
        $config['max_size'] = '2048';

        $this->load->library('upload', $config);

        if(! $this->upload->do_upload('avatar'))
        {

            $error = array('error' => $this->upload->display_errors());
            $this->session->set_flashdata('error', $error);
         
            $this->load->view('admin_access/admin_add_new');
        }   
        else
        {
            $avatar_upload = $this->upload->data();

            $data = array(
            'admin_name' => $this->input->post('admin_name'),
            'admin_username' => $this->input->post('admin_username'),
            'admin_email' => $this->input->post('admin_email'),
            'admin_password' => $this->input->post('password'),
            'admin_profile_pic' => $this->input->post('avatar'),
            'admin_profile_pic' => $config['upload_path'].$avatar_upload['file_name']);

            $this->db->insert('admin_profile',$data);

            echo "<script>alert('New Admin Successfully Enrolled')</script>";
            $this->load->view('admin_access/profile/admin_add_new');
        }
        
    }
}
?>
dluptydi

dluptydi1#

$result = $this->add_model->save($fields,array('id' => $id));
          
            if($result)
            {
                $this->session->set_flashdata('message', array('message' => 'Updated Successfully','class' => 'alert alert-success fade in'));
            }
            else
            {
                $this->session->set_flashdata('message', array('message' => 'Something went wrong, please try again','class' => 'alert alert-danger fade in'));
            }
qgelzfjb

qgelzfjb2#

控制器:

if($result <= 0) {
    $this->session->set_flashdata('error', 'There is error');
} else {
    $this->session->set_flashdata('success', 'Yey!');
}

我的示例视图(是的,我正在使用引导程序):

<div class="col-sm-12">
    <?php
        $this->load->helper('form');
        $error = $this->session->flashdata('error');
        if($error) {
    ?>
    <div class="alert alert-danger alert-dismissable">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <?php echo $this->session->flashdata('error'); ?>                    
    </div>
    <?php } ?>
    <?php  
        $success = $this->session->flashdata('success');
        if($success)
        {
    ?>
    <div class="alert alert-success alert-dismissable">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <?php echo $this->session->flashdata('success'); ?>
    </div>
    <?php } ?>
                            
    <div class="row">
        <div class="col-md-12">
            <?php echo validation_errors('<div class="alert alert-danger alert-dismissable">', ' <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>'); ?>
        </div>
    </div>
</div>

相关问题