First of all, I made research but couldn't find anything about it.
I'm sending flash data to users when they update or add something. My controller file's related part is like this;
function hizmet_ekle()
{
if($this->mhizmetler->hizmet_ekle())
{
$this->session->set_flashdata('ok', 'hizmet sisteme eklendi!');
redirect('panel/hizmetler');
}
else
{
$this->session->set_flashdata('hata', 'Bir hata oluştu. Lütfen tekrar deneyin!');
redirect('panel/hizmetler');
}
}
And my view's related parts are like this;
<?php if($this->session->flashdata('ok')): ?>
<div class="alert alert-success fade in widget-inner">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="fa fa-check"></i> <?php echo $this->session->flashdata('ok');?>
</div>
<?php endif; if($this->session->flashdata('hata')): ?>
<div class="alert alert-danger fade in widget-inner">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="fa fa-times"></i> <?php echo $this->session->flashdata('hata');?>
</div>
<?php endif; echo validation_errors('
<div class="alert alert-danger fade in widget-inner">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="fa fa-times"></i> ', '
</div>'); ?>
My system has a few different languages, it means I have to send different notification messages(session flashdata's) for each language but I can't use lang key in my controller file. How can I handle it?
Thanks in advance.
I found it!
I have to use it like this;
$this->session->set_flashdata('ok', $this->lang->line("greek"));
Related
Hye everyone! I want to make success message, the message appear but the green box did not appear as shown below.
blade.php:-
#if(Session::has('success'))
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert">
<i class="fa fa-times"></i>
</button>
<strong>Success!</strong> {{ session('success') }}
</div>
#endif
<br>
I am using Laravel v8.16.1 and PHP v7.3.1 when I am trying to get a message in the blade template.
#if(session('error'))
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h5><i class="icon fas fa-ban"></i> Success!</h5>
{{ session('success') }}
</div>
#endif
Using the below code, it's working for me.
$req->session()->flash('error', 'Invalid Username or Password');
return view('admin.views.login');
However, it's not the right way, and when I am trying to redirect back using the below code, then it's not working
return redirect()->back()->with('error', 'Invalid Username or Password');
Please help what is missing or what is wrong?
You can use to show errors
#if(count($errors) > 0 )
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<ul class="p-0 m-0" style="list-style: none;">
#foreach($errors->all() as $error)
<li>{{$error}}</li>
#endforeach
</ul>
</div>
#endif
And the redirect code would be
return redirect()->back()->withErrors(['errors' => 'There is some error in the details.']);
I am designing a page where the user will click on a delete link a modal should appear confirming the deletion. but when I click on the confirm button on the modal nothing happens.
here is my code:
view page:
<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="removeTeacherModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Remove Teacher</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="remove-messages"></div>
<p>Do you really want to remove ?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="removeTeacherBtn">confirm</button>
</div>
</div>
controller page:
$button ='
<div class="dropdown text-center">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria- expanded="false">
Action
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu2">
<li><a class="dropdown-item" type="button" data-toggle="modal" data- target="#updateTeacherModal" onClick="editTeacher('.$value['staff_id'].')">Edit</a></li>
<li><a class="dropdown-item" type="button" data-toggle="modal" data- target="#removeTeacherModal" onClick="removeTeacher('.$value['staff_id'].')">Remove</a></li>
</div> ';
the above part is a property that will be added dynamically on the page afterwards
this function also is included in the controller page
public function removeT($teacherId = null){
$validator= array('success' => FALSE , 'messages' => array());
if($teacherId){
$remove= $this->model_staff->remove($teacherID);
if($remove){
$validator['success']=true;
$validator['messages']='Teacher is removed Successfully';
}
else{
$validator['success']=false;
$validator['messages']='Error while removing the information';
}
}
echo json_encode($validator);
}
Model:
public function remove($teacherId = null){
if($teacherId){
$this->db->where('staff_id', $teacherId);
$result = $this->db->delete('staff');
return ($result == true) ? true : false;
}
}
Javascript:
function removeTeacher(teacherId = null){
if(teacherId){
$('#removeTeacherBtn').unbind('click').bind('click', function() {
$.ajax({
url: base_url + 'staff/removeT/'+teacherId ,
type:'post',
dataType :'json' ,
success: function(response){
if (response.success == true){
$('#messages').html('<div class="alert alert-success alert-dismissible fade show" role="alert">'+
'<button type="button" class="close" data-dismiss="alert" aria- label="Close"><span aria-hidden="true">×</span></button>'+ response.messages +
'</div>');
manageTeacherTable.ajax.reload(null,false);
$('#removeTeacherModal').modal('hide');
}
else {
$('#remove-messages').html('<div class="alert alert- warning alert-dismissible fade show" role="alert">'+
'<button type="button" class="close" data-dismiss="alert" aria- label="Close"><span aria-hidden="true">×</span></button>'+ response.messages +
'</div>');
}
}
});
});
}
}
Does anyone know where and how to style the redirect with global such as:
return Redirect::route('home')
->with('global', 'Your content has been posted!');
I want to use the bootstrap alerts with the global message
I just needed to put the styling after the global
Here is what I did:
return Redirect::route('admin-console-post')
->with('global', '
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
Your content has been posted successfully!
</div>
');
You need to style it in view like this:
#if(Session::has('global'))
<div class="output">
{{ Session::get('global') }}
</div>
#endif
Where output is class in which you put style of your choice.
Hope it helps ^^.
I have simple alert message which should show up only when there is error. However I don't know how to hide message on initialization. If I manually hide the message then error message stays hidden even when there is error.
<div class="alert alert-error">
<button class="close" data-dismiss="alert" type="button">×</button>
<?php echo $error?>
</div>
Try this
<?php if(isset($error)): ?><div class="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<?php echo $error; ?>
</div>
<?php endif; ?>
make sure that you include bootstrap.js and jquery.js correctly