Skip to Content
PHPCODE
CodeIgniter Provide Feedback to User
codeigniter code / August 1, 2018

Provide Feedback to user in Codeignter

step 1:- Controller created file name admin store_article function
public function store_article()
{
$this->load->library(‘form_validation’);
$this->form_validation->set_error_delimiters(“<p class=’text-danger’>”,”</p>”);
if($this->form_validation->run(‘add_article_rules’))
{
$post=$this->input->post();
$this->load->model(‘articlesmodel’,’articles’);
if($this->articles->add_article($post))
{
//flash message insert successfull
$this->session->set_flashdata(‘feedback’,”Article Added successfull.”);
$this->session->set_flashdata(‘feedback_class’,’alert-success’);
}
else
{
//insert failed.
$this->session->set_flashdata(‘feedback’,”Article failed To Add, Please Try Again.”);
$this->session->set_flashdata(‘feedback_class’,’alert-danger’);
}
return redirect(‘admin/dashboard’);
}
else
{
$this->load->view(‘admin/add_article’);
}
}

step 2 :created dashboard.php in view

<?php include_once(‘admin_header.php’);?>
<div class=”container”>
<div class=”row”>
<div class=”col-md-12 col-lg-offset-6″>
<?= anchor(‘admin/store_article’,’Add Article’,[‘class’=>’btn btn-warning float-right’]); ?>
<!– <a href=”<?php //echo base_url(‘admin/add_article’);?>” class=”btn btn-warning float-right”>Add Article</a> –>
</div>
</div>
<?php if($feedback=$this->session->flashdata(‘feedback’)):
$feedback_class=$this->session->flashdata(‘feedback_class’);
?>
<div class=”row”>
<div class=”col-lg-12″>
<div class=”alert alert-dismissible <?php echo $feedback_class;?>”>
<button type=”button” class=”close” data-dismiss=”alert”>&times;</button>
<?= $feedback;?>
</div>
</div>
</div>
<?php endif;?>
<table class=”table”>
<thead>
<th>Sr. No.</th>
<th>Title</th>
<th>Action</th>
</thead>
<tbody>
<?php if(count($articles)):?>
<?php foreach($articles as $article):?>
<tr>
<td>1</td>
<td><?php echo $article->title?></td>
<td>
<a href=”#” class=”btn btn-primary”>Edit</a>
<a href=”#” class=”btn btn-danger”>Delete</a>
</td>
</tr>
<?php endforeach; ?>
<?php else:?>
<tr>
<td colspan=”3″>Not Record Found</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<?php include_once(‘admin_footer.php’);?>

PHPCODE © 2024