I am trying to display messages in the error section from sender and receiver, both returning view mes_res from MessageController, but it is displaying an error message.
#controller method:
public function respone_msg($myid){
$dd = DB::table('messeges')->where(['is_read'=>0,'sender_id' =>$myid , 'receiver_id' => Session::get('id')])->get();
$myCount = count($dd);
var_dump($myCount);
$sendmsesgesreal = DB::table('messeges')->where(['sender_id' => Session::get('id') , 'receiver_id' => $myid])->orWhere(['receiver_id' => Session::get('id') ])->get();
//return view('users.mes_res')->with(['msg_data' => $sendmsesgesreal, 'user_id' => $myid, 'conv_id' => $sendmsesgesreal[0]->conversation_id]);
return view('users.mes_res')->with(['msg_data' => $sendmsesgesreal, 'user_id' => $myid, 'conv_id' => $sendmsesgesreal[0]->conversation_id])->header('Cache-Control', 'no-cache, no-store, must-revalidate');
}
view mes_reg:
<div class="messages-headline">
<i class="icon-feather-trash-2"></i> Delete Conversation
</div>
<!-- Message Content Inner -->
<div class="message-content-inner">
<?php
foreach ($msg_data as $msg) {
//
if($msg->sender_id==Session::get('id') && $msg->receiver_id==$user_id) //conv_id
{
$getuserdat1 = DB::table('profile_users')->where('user_id',$msg->sender_id)->get();
// print_r($msg);
if (count($getuserdat1)>0)
{
$fullname=$getuserdat1[0]->fname.' '.$getuserdat1[0]->lname;
if ($getuserdat1[0]->profile_images)
{
$img11 = url('')."/public/uploads/".$getuserdat1[0]->profile_images;
}
else
{
$img11 = url('')."/public/users/images/user-avatar-placeholder.png";
}
}
else
{
$img11 = url('')."/public/users/images/user-avatar-placeholder.png";
}
echo '<input type="hidden" name="receiver_id" id="receiver_id" value="'.$msg->sender_id.'">';
//print_r($img11);
?>
<div class="message-time-sign">
<span>{{ \Carbon\Carbon::parse($msg->CreatedBydate)->diffForhumans() }}</span>
</div>
<div class="message-bubble me">
<div class="message-bubble-inner">
<div class="message-avatar"><img src="{{$img11}}" alt="" /></div>
<div class="message-text"><p>{{$msg->messeges}}</p></div>
</div>
<div class="clearfix"></div>
</div>
<?php }
elseif($msg->sender_id==$user_id)
//else
{
//print_r($msg);
// $receiverdata = DB::table('messeges')
// ->where('sender_id',$msg->sender_id)->get();
// print_r($receiverdata);
//print_r($msg);
$getuserdat11 = DB::table('profile_users')->where('user_id',$msg->sender_id)->get();
if(count($getuserdat11)>0)
{
if ($getuserdat11[0]->profile_images)
{
$img111 = url('')."/public/uploads/".$getuserdat11[0]->profile_images;
}
else
{
$img111 = url('')."/public/users/images/user-avatar-placeholder.png";
}
}
else
{
$img111 = url('')."/public/users/images/user-avatar-placeholder.png";
}
echo '<input type="hidden" name="receiver_id" id="receiver_id" value="'.$msg->sender_id.'">';
//print_r($img111);
?>
<div class="message-time-sign">
<span>{{ \Carbon\Carbon::parse($msg->CreatedBydate)->diffForhumans() }}</span>
</div>
<div class="message-bubble">
<div class="message-bubble-inner">
<div class="message-avatar"><img src="{{$img111}}" alt="" /></div>
<div class="message-text"><p>{{$msg->messeges}}</p></div>
</div>
<div class="clearfix"></div>
</div>
<?php }
?>
</div>
Related
Currently trying to figure out how to update existing SQL data in cake php. I have my input fields being automatically filled with preexisting data but whenever I hit save to change existing data it does nothing. NO error or warning message.
Here is my Controller:
public function settings()
{
$user = $this->UserAuth->getUser();
$userid = $this->UserAuth->getUserId();
//$userEntity = $this->Push->find()->where(['user_id = ' => $userid])->order('time')->toArray($this->request->data, ['validate'=>false]);
//$query = $this->Push->find('all', ['conditions' => ['Push.user_id' => $userid]])->last();
$userEntity = $this->Push->find('all', ['conditions' => ['Push.user_id' => $userid]])->last();
if($this->request->is('patch', 'post', 'put')) {
$errors = $userEntity->errors();
if($this->request->is('ajax')) {
if(empty($errors)) {
$response = ['error'=>0, 'message'=>'success'];
} else {
$response = ['error'=>1, 'message'=>'failure'];
$response['data']['push'] = $errors;
}
echo json_encode($response);exit;
} else {
if(empty($errors)) {
if(!empty($this->request->data($userEntity['iosapikey']))) {
$userEntity['iosapikey'] = $this->request->data['Push']['iosapikey'];
}
if(!empty($this->request->data['Push']['androidapikey'])) {
$userEntity['androidapikey'] = $this->request->data['Push']['androidapikey'];
}
if(!empty($this->request->data['Push']['restapikey'])) {
$userEntity['restapikey'] = $this->request->data['Push']['restapikey'];
}
if(!empty($this->request->data['Push']['segments'])) {
$userEntity['iosapikey'] = $this->request->data['Push']['segments'];
}
if(!empty($this->request->data['Push']['tags'])) {
$userEntity['androidapikey'] = $this->request->data['Push']['tags'];
}
if(!empty($this->request->data['Push']['deeplinks'])) {
$userEntity['restapikey'] = $this->request->data['Push']['deeplinks'];
}
if($this->Push->save($userEntity, ['validate'=>false])) {
$this->Flash->success(__('Push settings have been updated successfully'));
//$this->redirect(['action'=>'index', 'page'=>$page]);
} else {
$this->Flash->error(__('Unable to update push settings, please try again'));
}
}
}
} else {
if(!empty($userEntity['iosapikey'])) {
$userEntity['iosapikey'] = $userEntity['iosapikey'];
}
if(!empty($userEntity['androidapikey'])) {
$userEntity['androidapikey'] = $userEntity['androidapikey'];
}
if(!empty($userEntity['restapikey'])) {
$userEntity['restapikey'] = $userEntity['restapikey'];
}
if(!empty($userEntity['segments'])) {
$userEntity['segments'] = $userEntity['segments'];
}
if(!empty($userEntity['tags'])) {
$userEntity['tags'] = $userEntity['tags'];
}
if(!empty($userEntity['deeplinks'])) {
$userEntity['deeplinks'] = $userEntity['deeplinks'];
}
}
$this->set(compact('userEntity'));
$this->set('_serialize', ['push']);
}
This is my template:
<div class="panel-body">
<?php echo $this->element('Usermgmt.ajax_validation', ['formId'=>'editPushForm', 'submitButtonId'=>'editPushSubmitBtn']); ?>
<?php echo $this->Form->create($userEntity, ['id'=>'editPushForm', 'class'=>'form-horizontal', 'type'=>'text']);?>
<div class="form-group col-md-9 col-sm-10">
<label>iOS API Key:</label>
<div class="">
<?php echo $this->Form->input('Push.iosapikey',['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control']);?>
</div>
</div>
<div class="form-group col-md-9 col-sm-10">
<label>Android API Key:</label>
<div class="">
<?php echo $this->Form->input('Push.androidapikey',['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control']);?>
</div>
</div>
<div class="form-group col-md-9 col-sm-10">
<label>REST API Key:</label>
<div class="">
<?php echo $this->Form->input('Push.restapikey',['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control']);?>
</div>
</div>
<div class="form-group col-md-9 col-sm-10">
<label>Segments:</label>
<div class="">
<?php echo $this->Form->input('Push.segments',['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control']);?>
</div>
</div>
<div class="form-group col-md-9 col-sm-10">
<label>Tags:</label>
<div class="">
<?php echo $this->Form->input('Push.tags',['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control']);?>
</div>
</div>
<div class="form-group col-md-9 col-sm-10">
<label>Deeplinks:</label>
<div class="">
<?php echo $this->Form->input('Push.deeplinks',['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control']);?>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-3 col-sm-offset-2 col-sm-3">
<?php echo $this->Form->Submit(__('Save'), ['div'=>false, 'class'=>'btn btn-primary pushbutton', 'id'=>'editPushSubmitBtn']); ?>
</div>
</div>
<?php echo $this->Form->end();?>
I'm sure I have a small error somewhere I just haven't spotted yet, but having put many hours into this with no positive result I thought it was time to find some help.
Cake PHP find function returns an object so i would request you to use a statement like $userEntity->iosapikey = $this->request->data['Push']['iosapikey']; to assign values and also enable debuging in cakephp https://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#debugging-queries-and-resultsets
I have 2 table(interview and interviewtrack) in 1 form.
here's my savehandler code so far :
public function saveHandler(Request $request, $obj)
{
try {
DB::beginTransaction();
$obj->fill($request->all());
if (!$obj->save()) {
throw new ValidationException($obj->errors());
}
foreach($request->interviewTracks as $interviewTrack) {
\Log::info($interviewTrack);
if (empty($interviewTrack['id'])) {
$interviewTrack = new InterviewTrack();
}
else {
$interviewTrack = InterviewTrack::find($interviewTrack['id']);
}
$interviewTrack->interview()->associate($obj);
$interviewTrack['interview_id'] = isset($interviewTrack['interview_id']);
$interviewTrack->status = $interviewTrack['status'];
$interviewTrack->track_date = isset($interviewTrack['track_date']) ? $interviewTrack['start_time'] : 'YYYY-MM-DD';
$interviewTrack->outcome = $interviewTrack['outcome'];
$interviewTrack->remarks = $interviewTrack['remarks'];
$interviewTrack->save();
};
if (!$interviewTrack->save()) {
throw new ValidationException($interviewTrack->errors());
}
DB::commit();
return $this->sendSuccessResponse($request);
} catch (ValidationException $e) {
DB::rollback();
\Log::error($e->errors);
return $this->sendErrorResponse($request, $e->errors);
} catch (Exception $e) {
DB::rollback();
\Log::error($e->getMessage());
return $this->sendErrorResponse($request,'Unable to process. Please contact system Administrator');
}
}
here's my view form code :
<?php $index = 0; ?>
<?php echo Form::hidden('interviewTracks['.$index.'][id]', null); ?>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label">Track Date</label>
<?php echo Form::text('interviewTracks['.$index.'][track_date]', null, ['id' => 'track_date','class' => 'form-control']); ?>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label">Status</label>
<?php echo Form::select('interviewTracks['.$index.'][status]', $interviewTrackList, null, ['id' => 'status','class' => 'form-control']); ?>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label">Outcome</label>
<?php echo Form::select('interviewTracks['.$index.'][outcome]', $outcomeList, null, ['id' => 'outcome','class' => 'form-control']); ?>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label">Remark</label>
<?php echo Form::text('interviewTracks['.$index.'][remark]', null, ['id' => 'remarks','class' => 'form-control']); ?>
</div>
</div>
</div>
<?php $index++; ?>
it throws error Invalid argument supplied for foreach() when I try to save.
any idea ??
Change:
foreach($request->interviewTracks as $interviewTrack)
to:
foreach($request->input('interviewTracks') as $interviewTrack)
I have a project in this i am stuck because i want to search by industry, educational level, Areas of Experience but it does not act in the way i want to do. I have a dropdown list named industry after selecting industry the educational level, Areas of Experience comes in a checkbox. After selecting the box i want to search and display the result. My Search controller is
public function searchProfessionals (Request $request)
{
$industry = $request->input('industry');
$educationLevels = $request->input('educationLevels');
$areasOfExperiences = $request->input('areasOfExperiences');
$startPrice = $request->input('start_price');
$endPrice = $request->input('end_price');
$meetingType = $request->input('meeting_type');
if ($meetingType == 1) {
$type = [1, 1];
} elseif ($meetingType == 2) {
$type = [2, 2];
} elseif ($meetingType === 3) {
$type = [1, 2];
} else {
$type = [1, 2];
}
$userMeetings = array();
$userRoles = array();
$users = array();
$showUsers = array();
$userHourRates = array();
$userIndus = UserIndustry::where('industry_id', $industry)->get();
$userDegrees = UserDegree::where('degree_id', $educationLevels)->get();
$userAreaOfExperiences = UserAreaOfExperience::where('area_of_experience_id', $areasOfExperiences)->get();
if (!empty($userIndus)) {
foreach ($userIndus as $userInd) {
if (!empty($userDegrees)) {
foreach ($userDegrees as $userDegree) {
if (!empty($userAreaOfExperiences)) {
foreach ($userAreaOfExperiences as $userAreaOfExperience) {
$userHourRates[] = UserTime::where('user_id', $userAreaOfExperience->user_id)->whereBetween('hour_rate', [$startPrice, $endPrice])->first();
}
}
$userHourRates[] = UserTime::where('user_id', $userDegree->user_id)->whereBetween('hour_rate', [$startPrice, $endPrice])->first();
}
}
$userHourRates[] = UserTime::where('user_id', $userInd->user_id)->whereBetween('hour_rate', [$startPrice, $endPrice])->first();
}
My blade template is
#extends ('frontends.layouts.app')
#section ('main')
<div id="content-block" class="margin-top-140">
<div class="container-fluid block custom-container">
<h3 class="block-title">Browse Professionals</h3>
<div class="block-subtitle"><span>Connect</span> <span>Learn</span> <span>Inspire</span> <span>Thrive</span> </div>
<div class="row">
{{--<form action="" method="post">--}}
<div class="col-md-2 left-feild">
<div class="margin-bottom-30">
<h3>Search Filters</h3>
</div>
#if(Auth::check() && Auth::user()->user_role->role_id == 1000000)
<div class="be-vidget">
<h3 class="letf-menu-article"> Looking To </h3>
<div class="creative_filds_block">
<div class="radio">
<label><input type="radio" name="lookingTo" onclick="lookingTo(2)"> Seek Advice</label>
</div>
<div class="radio">
<label><input type="radio" name="lookingTo" onclick="lookingTo(3)"> Share Advice</label>
</div>
</div>
</div>
<script>
function lookingTo(e) {
$.ajax({
type: 'POST',
url: '{{ URL::to('looking/to') }}/' + e,
success: function (result) {
$('#browse_professionals').html(result);
}
});
}
</script>
#endif
<div class="be-vidget">
<h3 class="letf-menu-article">Professionals</h3>
<div class="-creative_filds_block">
<div class="fp-panel-wrap">
<a class="toggle-btn active" onclick="open_industry()" href="#" data-target="#ul_industry" id="a_industry">Industry</a>
<ul id="ul_industry" class="fp-panel open" style="overflow:scroll; height:200px;">
#if(!empty($industries))
#foreach($industries as $industry)
<li value="{{ $industry->id }}">{{ (!empty($industry['name'])) ? $industry['name'] : '' }} </li>
#endforeach
#endif
</ul>
<script>
function industry_search(e) {
$.ajax({
type: 'POST',
url: '{{ URL::to('professionals/industry') }}/' + e,
success: function (result) {
$('#education_experience').html(result);
$('#a_industry').attr('class', 'toggle-btn');
$('#ul_industry').css('display', 'none');
$('#education_experience').css('display', 'block');
$('#eduLevel').css('display', 'block');
$('#areaExperience').css('display', 'block');
}
});
}
function open_industry() {
$('#education_experience').css('display', 'block');
$('#education_experience').css('display', 'block');
$('#eduLevel').css('display', 'none');
$('#areaExperience').css('display', 'none');
}
</script>
<div id="education_experience" style="">
<a id="a_education" class="toggle-btn" href="#" data-target="#eduLevel">Education Level</a>
<ul id="eduLevel" class="no-link fp-panel" style="overflow:scroll; height:200px;">
#if(!empty($degrees))
#foreach($degrees as $degree)
<li value="{{ $degree->id }}">{{ (!empty($degree['name'])) ? $degree['name'] : '' }}</a> </li>
#endforeach
#endif
</ul>
<a id="a_experience" class="toggle-btn" href="#" data-target="#areaExperience">Areas of Experience</a>
<ul id="areaExperience" class="no-link fp-panel" style="overflow:scroll; height:200px;">
</ul>
</div>
</div>
</div>
</div>
<div class="be-vidget">
<h3 class="letf-menu-article">Meeting Preferences</h3>
<label>Price</label>
<br> <br>
<input type="hidden" id="price_ranger" class="range-slider" value="23"/>
<label style="margin-top: 30px;">Type</label>
<div class="form-group">
<select class="form-input" id="meeting_type">
<option value="3">All</option>
<option value="1">Phone Meeting</option>
<option value="2">Web Meeting</option>
</select>
</div>
</div>
<button id="search_professionals" type="button" class="btn color-2 size-2 btn-block hover-1">Apply Filter</button>
#if(Session::has('remove_filter'))
<button type="button" class="btn btn-danger size-2 btn-block hover-1">Remove Filter</button>
#endif
<script>
var industry = '';
$('#ul_industry li').click(function() {
industry = $(this).attr('value');
// console.log(industry);
});
$("#search_professionals").click(function () {
var degrees = new Array();
$('input[name="degrees_checkbox"]:checked').each(function() {
degrees.push(this.value);
});
var experiences = new Array();
$('input[name="experiences_checkbox"]:checked').each(function() {
experiences.push(this.value);
});
var price_ranger = $("#price_ranger").val();
var price_ranger_array = price_ranger.split(",");
var start_price = price_ranger_array[0];
var end_price = price_ranger_array[1];
var meeting_type = $("#meeting_type").val();
$.ajax({
'type' : 'post',
'url' : '{{ URL::to('search/professionals') }}',
'data' : {
'industry' : industry,
'educationLevels' : degrees,
'areasOfExperiences' : experiences,
'start_price' : start_price,
'end_price' : end_price,
'meeting_type' : meeting_type
},
'success' : function (result) {
console.log(result);
$('#browse_professionals').html(result);
}
});
});
</script>
</div>
{{--</form>--}}
<div class="col-md-10">
<div id="browse_professionals" class="row _post-container_">
#if (!empty($valid_providers))
#foreach ($valid_providers as $provider)
<div class="category-1 custom-column-5">
<div class="be-post">
<figure class="ratio-4-3 be-img-block-alt">
<div class="ratio-inner" style="background-image: url('{{ !empty($provider->user_detail->avatar) ? URL::to($provider->user_detail->avatar) : '' }}')">
<img src="{{ !empty($provider->user_detail->avatar) ? URL::to($provider->user_detail->avatar) : '' }}" alt="{{ !empty($provider->username) ? URL::to($provider->username) : '' }}">
</div>
</figure>
<div class="be-post-title">{{ (!empty($provider->user_share->share)) ? str_limit($provider->user_share->share, 90) : '' }}</div>
<div class="author-post">
<span>{{ !empty($provider->user_detail->first_name) ? $provider->user_detail->first_name : '' }} {{ !empty($provider->user_detail->last_name) ? $provider->user_detail->last_name : '' }}</span>
</div>
<span>{{ (!empty($provider->user_detail->credentials)) ? str_limit($provider->user_detail->credentials, 25) : '' }}</span>
<div data-value="4" class="static-rating"></div>
<div class="info-block clearfix">
<a class="btn color-1 size-2 hover-1 pull-right" href="{{ !empty($provider->username) ? URL::to($provider->username) : '' }}">Contact</a>
<h3 class="rate"> ${{ (!empty($provider->user_time->hour_rate)) ? $provider->user_time->hour_rate : '' }} /hr</h3>
</div>
</div>
</div>
#endforeach
#endif
</div>
</div>
</div>
</div>
</div>
#endsection
please help me. I am stuck this very badly. Sorry for my bad English
The answer will be
public function searchProfessionals(Request $request)
{
$industry = $request->input('industry');
$educationLevels = $request->input('educationLevels');
$areasOfExperiences = $request->input('areasOfExperiences');
$startPrice = $request->input('start_price');
$endPrice = $request->input('end_price');
$meetingType = $request->input('meeting_type');
$userDetails = array();
$userMeetings = array();
$userRoles = array();
$users = array();
$showUsers = array();
$userHourRates = array();
$userDegrees = array();
$userIndustryArray = array();
$userExperience = array();
$userAr = array();
$data['usersDegress'] = '';
$data['usersExperience'] = '';
$intersect_array = array();
$data['userDetails'] = UserDetail::all();
$data['userTime'] = UserTime::whereBetween('hour_rate',[$startPrice,$endPrice])->get();
$userPriceArray = array();
foreach ($data['userTime'] as $price) {
foreach ($data['userDetails'] as $userDetail) {
if ($price->user_id == $userDetail->user_id) {
$userPriceArray[] = $userDetail;
}
}
}
$newArray = array();
$data['userMeeting'] = UserMeeting::where('meeting_id', $meetingType)->get();
foreach ($userPriceArray as $price) {
foreach ($data['userMeeting'] as $meet) {
if ($price->user_id == $meet->user_id) {
$newArray[] = $price;
}
}
}
if(!empty($industry)) {
$data['userIndustry'] = UserIndustry::where('industry_id',$industry)->get();
foreach ($data['userIndustry'] as $userIn){
foreach ($newArray as $new){
if($new->user_id == $userIn->user_id){
$userIndustryArray[] = $new ;
}
}
}
if(count($educationLevels) >0){
$data['usersDegress'] = UserDegree::whereIn('degree_id',$educationLevels)->get();
foreach ($data['usersDegress'] as $education ){
foreach ($userIndustryArray as $n){
if($n->user_id == $education->user_id){
$userDegrees[] = $n ;
}
}
}
}
if(count($areasOfExperiences) >0){
$data['usersExperience'] = UserAreaOfExperience::whereIn('area_of_experience_id',$areasOfExperiences)->get();
foreach ($data['usersExperience'] as $experience ){
foreach ($userIndustryArray as $ex){
if($ex->user_id == $experience->user_id){
$userExperience[] = $ex ;
}
}
}
}
}else{
$userIndustryArray = $newArray ;
}
if(count($educationLevels)> 0 && count($areasOfExperiences) >0) {
$intersect_array = array_intersect ($userDegrees,$userExperience);
$userIndustryArray =$intersect_array;
}else if(count($educationLevels) == 0 && count($areasOfExperiences) >0) {
$intersect_array = $userExperience;
$userIndustryArray =$intersect_array;
}
else if(count($educationLevels)> 0 && count($areasOfExperiences) == 0) {
$intersect_array = $userDegrees;
$userIndustryArray =$intersect_array;
}else if(count($educationLevels) == 0 && count($areasOfExperiences) == 0) {
$userIndustryArray =$userIndustryArray;
}
$string = '' ;
foreach ($userIndustryArray as $item){
$userRatingShow = Review::where('provider_id',$item->user_id)->avg('rating');
if(empty($userRatingShow)){
$userRatingShow = 0;
}
$avatar = '';
$name = '';
$user = User::find($item->user_id) ;
if(!empty($user)){
$name = $user->username ;
}
if(!empty($item->avatar )){
$avatar = url($item->avatar);
}else{
}
$userTime= UserTime::where('user_id',$item->user_id)->orderby('id','desc')->first();
if(!empty($userTime)){
$userTimeShow = $userTime->hour_rate ;
}
$bio = '';
$user_share = UserShare::where('user_id',$item->user_id)->orderby('id','desc')->first();
if(!empty($user_share)) {
$bio =str_limit($user_share->share,85);
}
$string .= '<div class="category-1 custom-column-5">
<div class="be-post">
<figure class="ratio-4-3 be-img-block-alt">
<div class="ratio-inner" style="background-image: url(' . $avatar . ')">
<img src="' . $avatar . '" alt="omg">
</div>
</figure>
<div class="be-post-title">' . $bio . '</div>
<div class="author-post">
<span>
<a href="' . url($name) . '">' .
$item->first_name . ' ' . $item->last_name . '
</a>
</span>
</div>
<span>' . $item->credentials . '</span>
</div>
<div data-value="' . $userRatingShow . '" class="static-rating"></div>
<div class="info-block clearfix">
<a class="btn color-1 size-2 hover-1 pull-right" href="' . url($name) . '">Contact</a>
<h3 class="rate">$' . $userTimeShow . '/hr</h3>
</div>
</div>
</div>
';
}
if(!empty($string)) {
return response($string);
}else{
echo '<div class="text-center margin-top-140"><h2>Sorry, no members meet your criteria.</h2></div>';
echo '<div class="text-center margin-top-50"><h2>Please revise your search.</h2></div>';
}
}
I'm having a problem showing an alert message after submitting a form.
I have a form for submitting a report, then after submission it will be stored in a table. What I want to happen is that after submitting a report, there will be an alert message for each new submitted report. I'm using CI as framework. Here is what I have:
View:
<div class="row-fluid">
<button type="button" class="btn btn-primary col-lg-2" data-toggle="collapse" data-target="#add_form" onclick="add_clicked()">Submit Report</button><br />
<div class="col-lg-6">
<?php
$attributes = array('class' => $class, 'id' => 'add_form', 'role' => 'form');
echo form_open('admin/report', $attributes);?>
<div class="form-group">
<input class="form-control" type="hidden" name="add_hidden" value="add-report">
</div>
<br><br>
<div class="form-group">
<?=form_input( array('id'=>'sender','class'=>'form-control' ,'name'=>'sender','type'=>'text','placeholder'=> 'Senders Name', 'value' => set_value('sender'), 'required'=> 'true') );?> <br />
<?=form_input( array('id'=>'date','class'=>'form-control date-picker','name'=>'date','type'=>'text','placeholder'=> 'Date', 'value' => set_value('date') ) );
$date = date('Y-m-d H:i:s');?><br />
<?=form_textarea( array('id'=>'subject','class'=>'form-control','name'=>'subject','type'=>'message-text','placeholder'=> 'Your Message here', 'value' => set_value('subject'), 'required'=> 'true') );?><br />
</div>
<div class="form-group">
<?=form_input( array('class'=>'btn btn-success','id'=>'add_submit','type'=>'submit','value'=>'submit')) ;?>
</div>
<?=form_close();?>
</div>
<div class="col-md-10 text-center" id="success" style="display:none">
<?php if(isset($message)) echo $message ?>
</div>
</div>
</div>
<br> <br>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th style="text-align: center">Sender</th>
<th style="text-align:center">Subject</th>
<th style="text-align:center">Date</th>
</tr>
</thead>
<tbody>
<?php
foreach ($query->result_array() as $row) {
echo '
<tr>
<td style="text-align:center">'.$row["sender"].'</td>
<td style="text-align:center">'.$row["subject"].'</td>
<td style="text-align:center">'.$row["date"].'</td>
<td> <button type="button" class="btn btn-success btn-small" data-toggle="modal" data-target="#view'.$row["sender"].'"> Read </button>
<button type="button" class="btn btn-danger btn-small" data-toggle="modal" data-target="#remove'.$row["sender"].'">delete</button></td>
</tr>
';
}
?>
This is my controller:
public function report()
{
$this->load->model('report_model', 'database');
$sql = "SELECT * FROM report";
$data['query'] = $this->database->view_report($sql);
if ($this->input->post('add_hidden')) {
$this->form_validation->set_rules('sender', 'sender', 'required');
$this->form_validation->set_rules('subject', 'subject', 'required');
$this->form_validation->set_rules('date', 'date');
$this->form_validation->set_error_delimiters('<div class="has-error" style="color: #FF0000">', '</div>');
if ($this->form_validation->run() == TRUE) {
//Setting values for table columns
$data = array(
'sender' => $this->input->post('sender'),
'subject' => $this->input->post('subject'),
'date' => $this->input->post('date'),
);
//Transfering data to Model
$q = $this->database->add_report($data);
$data['query'] = $this->database->view_report($sql);
if ($q) {
$data['message'] = '<h3> Your report has successfully submitted!</h3>';
$data['success'] = '';
$data['class'] = 'collapse';
$this->load->view('report_view', $data);
} else {
$data['message'] = '<h3> Report submission unsuccessful!</h3>';
$data['success'] = '';
$data['class'] = 'collapse';
$this->load->view('report_view', $data);
}
}
else {
$data['message'] = '';
$data['success'] = 'none';
$data['class'] = '';
$this->load->view('report_view', $data);
}
}
else if ($this->input->post('del_hidden')) {
$from = $this->input->post('del_sender');
$subject = $this->input->post('del_subject');
$date = $this->input->post('del_date');
$qry = "DELETE FROM report WHERE sender = '$from'";
$q = $this->database->delete_report($qry);
$sql = "SELECT * FROM report";
$data['query'] = $this->database->view_report($sql);
if ($q) {
$data['message'] = '<h3> "' . $subject . '"message deleted from database!!</h3>';
$data['success'] = '';
$data['class'] = 'collapse';
$this->load->view('report_view', $data);
}
} else {
$data['success'] = 'none';
$data['class'] = 'collapse';
$this->load->view('report_view', $data);
}
}`
Actually you are displaying the message in view ; this part of your code is sufficient for that.
<div class="col-md-10 text-center" id="success" style="display:none">
<?php if(isset($message)) echo $message ?>
</div>
But the div has style display:none so it will not be displayed. So change it to
<?php if(isset($message))
{
?>
<div class="col-md-10 text-center" id="success">
<?php echo $message ?>
</div>
<?php
}
?>
if you want an alert message then you can change it to
<?php if(isset($message))
{
?>
<script>
alert('<?php echo $message ?>');
</script>
<?php
}
?>
If it is an javascript alert, search for the alert expression with the alerted message, put an . And use console.log()...
How to do pagination in Yii without any grid view and listview
I was stack in their for two days
these is my controller
public function actionIndex()
{
$criteria = new CDbCriteria;
// $criteria ->order = 'date';
$pages = new CPagination(OfferEvents::model()->count());
$pages ->pageSize = 2;
$pages -> applyLimit($criteria);
$post= OfferEvents::model()->findAll($criteria);
$this -> render('index', array('post' => $post, 'pages' => $pages));
}
and my view
<?php foreach($models as $model): ?>
<?php for($x = 0; $x < $arrlength; $x++) { ?>
<?php if($catiddet == 1){?>
<div class="col-sm-4">
<div class="list-box fadeInDown ">
<div class="img-box-1">
<img src="<?php echo $offerListArray[$x]['offerimg']; ?>" style="width:360px;height:202px;" />
<a href="#" class="view-btn" d='modal-launcher' data-toggle="modal"
data-target="#detailsOffeEve" onClick="showdetails(<?php echo $offerListArray[$x]['id']; ?>)">View Event</a>
</div>
<div class="text-box">
<?php
$date2=$offerListArray[$x]['enddate'] ;
$diff = (strtotime($date2)- strtotime($now))/24/3600;
?>
<div class="round-box clear"><span><h1><?php echo $diff ?><small>Days</small></h1></span></div>
<p style="height:19px;overflow: hidden;"> <b ><?php echo $offerListArray[$x]['offertitle']; ?> </b></p>
<p style="height: 80px;overflow: hidden;"><?php echo $offerListArray[$x]['description']; ?> </p>
</div>
</div>
</div>
<?php } else{?>
<div class="col-sm-4" >
<div class="list-box">
<div class="img-box-1">
<?php $filepathnw=$offerListArray[$x]['offerimg'];
//if (file_exists($filepathnw)) { $filepathSrc=Yii::app()->baseUrl.'/'.$filepathnw; } else
//{ $filepathSrc='http://www.childnet.com/pimages/1351720/thumbnail4.jpg'; }
?>
<img src="<?php echo $filepathnw; ?>" />
<a href="#" class="view-btn" d='modal-launcher' data-toggle="modal"
data-target="#detailsOffeEve" onClick="showdetails(<?php echo $offerListArray[$x]['id']; ?>)">View Offer</a>
</div>
<div class="text-box" style="padding:2px !important;">
<?php
$date2=$offerListArray[$x]['enddate'] ;
$diff = (strtotime($date2)- strtotime($now))/24/3600;
?>
<span><h1><?php echo $diff ?><small>Days</small></h1></span>
<span><h1><?php echo $offerListArray[$x]['discountper']; ?>%<small>DISCOUNT</small></h1></span>
<span><h1>$<?php echo $offerListArray[$x]['discountperamt']; ?><small>You Save</small></h1></span>
<div class="text-box" style="padding:15px;">
<p style="height:19px;overflow: hidden;">
<b ><?php echo $offerListArray[$x]['offertitle']; ?> </b></p>
<p style="height: 80px;overflow: hidden;"><?php echo $offerListArray[$x]['description']; ?> </p>
</div> </div>
</div>
</div>
<?php } ?>
<?php } ?>
<?php endforeach; ?>
// display pagination
<?php $this->widget('CLinkPager', array(
'pages' => $pages,
)) ?>
out put comes fine..but the data repeats...
select * FROM offer_events WHERE enddate >= '$now' AND (title like '%$locationdet%' OR description like '%$locationdet%') AND type = '$catiddet' ORDER BY id DESC LIMIT 6 ");
$datalat = $dbCommand->queryAll(); $numlatData=count($datalat);
// echo "<pre>"; print_r($datalat); echo "</pre>";
$latlongdats='';
if($numlatData!=0){
foreach($datalat as $expertn)
{
$ids=$expertn['id'];
$offertitle=$expertn['title'];
if($expertn['image']!=""){ $imgUrl=$expertn['image']; } else { $imgUrl='image-not-available.png'; }
$infowinimgpath='theme/images/OfferEvents/thumb/'.$imgUrl;
if (file_exists($infowinimgpath)) { $infowinimgpathSrc=Yii::app()->baseUrl.'/'.$infowinimgpath; } else
{ $infowinimgpathSrc=Yii::app()->baseUrl.'/theme/images/OfferEvents/thumb/image-not-available.png'; }
$offerimg=$infowinimgpathSrc;
$latinow=$expertn['latitude'];
$longinow=$expertn['longitude'];
$latlongdats.="['".$ids."', ".$latinow.",".$longinow.",'".$offertitle."','".$offerimg."','".$expertn['startdate']."'],";
$offertList = array(
"id" => $ids,
"offertitle"=> $offertitle,
"offerimg" => $offerimg,
"description" => $expertn['description'],
"startdate" => $expertn['startdate'],
"enddate" => $expertn['enddate'],
"discountper" => $expertn['discountper'],
"discountperamt" => $expertn['discountperamt']
);
array_push($offerListArray,$offertList);
}
$zoomlevel=3;
$latlongdatsfinal=rtrim($latlongdats, ",");
} else { $latlongdatsfinal="['','',''],"; $ErrorMsgmap="No Result Found."; }
}
and could you please explain me how this happend???
You can use CActiveDataProvider to perform your pagination needs
public function actionIndex()
{
$criteria = new CDbCriteria;
// $criteria ->order = 'date';
$post= new CActiveDataProvider('OfferEvents', array(
'criteria' => $criteria,
'pagination'=>array('pageSize' => 2),
));
$this -> render('index', array('post' => $post));
}
In your view, instead of using foreach loop, use ListView / GridView and pass the CActiveDataProvider instance ($post) in your case
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$post,
'itemView'=>'_post', // refers to the partial view named '_post'
));
the "_post.php" subview file would contain
$data->property // whatever properties you have set for 'OfferEvents'