Pagination search reverting to previous search on page 2 - cakephp

I have a listing of all users, and it's done with cakephp 1.3 pagination-and a search function. It works perfectly in FF/Opera/Chrome, but has the following issue in IE8/IE9
step 1. Make a search that brings up > 1 page.
step 2. Make a second search that brings up > 1 page.
step 3. Click the next page/page 2 button.
It brings up the second page of step 1. If you go to page 1, you are results of step 1.
I can't find anything on why IE would behave this way. I checked my session values, but they are correct as far as I can tell (ex. step 1 session = 145, step 2 session = 7, step 3 session = 7)
Controller (I've stripped out stuff to make it smaller, I can add in more if needed):
if(empty($this->data)) {
$this->data['User']['inactive'] = $this->Session->read('User.inactive_store');
$this->data['User']['pe'] = $this->Session->read('User.pe_store');
$this->data['User']['district'] = $this->Session->read('User.district_store');
$this->data['User']['ghq'] = $this->Session->read('User.ghq_store');
$this->data['User']['last_name'] = $this->Session->read('User.last_name_store');
$this->data['User']['first_name'] = $this->Session->read('User.first_name_store');
$this->data['User']['rank'] = $this->Session->read('User.rank_store');
$this->data['User']['status'] = $this->Session->read('User.status_store');
$this->data['User']['race'] = $this->Session->read('User.race_store');
$this->data['User']['sex'] = $this->Session->read('User.sex_store');
$this->data['User']['type'] = $this->Session->read('User.type_store');
$this->data['User']['radio'] = $this->Session->read('User.radio_store');
$this->data['User']['unit'] = $this->Session->read('User.unit_store');
$this->data['User']['results'] = $this->Session->read('User.results_store');
if(empty($this->data['User']['results'])){$this->data['User']['results'] = 0;}
$this->data['User']['psid'] = $this->Session->read('User.psid_store');
$this->data['User']['psid_show'] = $this->Session->read('User.psid_show_store');
$this->data['AirCard']['card_number'] = $this->Session->read('User.card_number_store');
$this->data['AirCard']['esn'] = $this->Session->read('User.esn_store');
$this->data['AirCard']['ip_address'] = $this->Session->read('User.ip_store');
}
$results = 'false';
$message = '';
if(!empty($this->data)){
//set up some variables
$pe = $this->data['User']['pe'];
$district = $this->data['User']['district'];
$ghq = $this->data['User']['ghq'];
$first_name_store = $this->data['User']['first_name'];
$last_name_store = $this->data['User']['last_name'];
$first_name = $this->data['User']['first_name'].'%';
$last_name = $this->data['User']['last_name'].'%';
$rank = $this->data['User']['rank'];
$status = $this->data['User']['status'];
$race = $this->data['User']['race'];
$sex = $this->data['User']['sex'];
$type = $this->data['User']['type'];
$results = $this->data['User']['results'];
$psid = $this->data['User']['psid'];
$psid_show = $this->data['User']['psid_show'];
$car = $this->data['User']['radio'];
$badge = $this->data['User']['unit'];
//hidden admin controls
if(empty($this->data['AirCard']['card_number']) && empty($this->data['AirCard']['esn']) && empty($this->data['AirCard']['ip_address']))
{
$card_number = '';
$esn = '';
$ip = '';
} else {
$card_number = $this->data['AirCard']['card_number'];
$esn = $this->data['AirCard']['esn'];
$ip = $this->data['AirCard']['ip_address'];
}
$run_mobile = 0;
//this message will display to ensure user what was searched for/what was changed in search
$message = $message.'<p> Searched for: </p>';
//while loop to check for names. for example someone searches Jon Burns, gets no results it should search for J Burns instead, no results just Burns, etc
while(empty($datas))
{
//check for any empty variables/fill the ones that need to have values
if(empty($pe))
{
$pe_empty = 1;
$pe_query = '';
} else {
$message = $message.'<b>PE</b> = '.$pe.' || ';
$pe_query = array('User.pe' => $pe);
}
if(empty($district))
{
$district_empty = 1;
$district_query = '';
} elseif(sizeof($district) == 1) {
$message = $message.'<b>District</b> = '.$district_list[$district].' || ';
$district_query = array('User.district_id' => $district);
} else {
$district_empty = 1;
}
if(empty($ghq))
{
$ghq_empty = 1;
$ghq_query = '';
} elseif(sizeof($ghq) == 1) {
$message = $message.'<b>Assigned To</b> = '.$ghq_list[$ghq].' || ';
$ghq_query = array('User.ghq_id' => $ghq);
} else {
$ghq_empty = 1;
}
if(empty($rank))
{
$rank_empty = 1;
$rank_query = '';
} elseif(sizeof($rank) == 1) {
$message = $message.'<b>Rank</b> = '.$rank_list[$rank].' || ';
$rank_query = array('User.rank_id' => $rank);
}
if(empty($first_name_store))
{
$first_empty = 1;
$first_name_query = '';
} else {
$message = $message.'<b>First Name</b> = '.$first_name_store.' || ';
$first_name_query = array('User.first_name LIKE' => $first_name);
}
if(empty($last_name_store))
{
$last_empty = 1;
$last_name_query = '';
} else {
$message = $message.'<b>Last Name</b> = '.$last_name_store.' || ';
$last_name_query = array('User.last_name LIKE' => $last_name);
}
if(empty($this->data['User']['inactive']))
{
$this->data['User']['inactive'] = 0;
}
if($this->data['User']['inactive'] == 0)
{
$active_query = array('User.active' => 1);
} else {
$active_query = '';
}
if(empty($status))
{
$status_query = '';
} else {
$message = $message.'<b>Status</b> = '.$status_list[$status].' || ';
$status_query = array('User.special_status_id' => $status);
}
if(empty($race))
{
$race_query = '';
} else {
$message = $message.'<b>Race</b> = '.$race_list[$race].' || ';
$race_query = array('User.race_id' => $race);
}
if(empty($sex))
{
$sex_query = '';
} else {
$message = $message.'<b>Sex</b> = '.$sex_list[$sex].' || ';
$sex_query = array('User.sex_id' => $sex);
}
if(empty($type))
{
$type_query = '';
} else {
$message = $message.'<b>Type</b> = '.$type_list[$type].' || ';
$type_query = array('User.employee_type_id' => $type);
}
if(empty($psid))
{
$psid_query = '';
} else {
$message = $message.'<b>Public Safety ID</b> = '.$psid.' || ';
$psid_query = array('User.psid' => $psid);
}
if(empty($psid_show))
{
$psid_show_query = '';
} else {
$message = $message.'<b>Public Safety ID not empty</b> || ';
$psid_show_query = array('User.psid !=' => null);
}
if(empty($car))
{
$car_query = '';
} else {
$message = $message.'<b>Car Number</b> = '.$car.' || ';
$car_query = array('User.radio =' => $car);
}
if(empty($badge))
{
$badge_query = '';
} else {
$message = $message.'<b>Badge Number</b> = '.$badge.' || ';
$badge_query = array('User.unit =' => $badge);
}
if(empty($card_number))
{
$card_number_query = '';
$this->data['AirCard']['card_number'] = '';
} else {
$message = $message.'<b>Card Number = </b>'.$card_number.' || ';
$card_number_query = array('AirCard.card_number' => $card_number);
$run_mobile = 1;
}
if(empty($esn))
{
$esn_query = '';
$this->data['AirCard']['esn'] = '';
} else {
$message = $message.'<b>ESN = </b>'.$esn.' || ';
$esn_query = array('AirCard.esn' => $esn);
$run_mobile = 1;
}
if(empty($ip))
{
$ip_query = '';
$this->data['AirCard']['ip_address'] = '';
} else {
$message = $message.'<b>IP = </b>'.$ip;
$ip_query = array('AirCard.ip_address' => $ip);
$run_mobile = 1;
}
$message = $message.'</p>';
$mobile_query = '';
if($run_mobile == 1)
{
$mobile_user_ids = $this->AirCard->find('list',array(
'conditions' => array('AND' => array(
$card_number_query,
$esn_query,
$ip_query
)),'fields' => array('user_id')
));
if(!empty($mobile_user_ids))
{
$mobile_query = array('User.id' => $mobile_user_ids);
} else {
$message = $message.'No results found';
}
}
//List of users matching given parameters $datas
$this->paginate = array(
'conditions' => array('AND' => array(
$pe_query,
$district_query,
$ghq_query,
$active_query,
$last_name_query,
$first_name_query,
$rank_query,
$status_query,
$race_query,
$sex_query,
$type_query,
$hide_technical,
$psid_query,
$psid_show_query,
$mobile_query,
$car_query,
$badge_query
)),
'fields' => array('pe','last_name','first_name','middle_initial','id','district_id','ghq_id','rank_id','sworn','cps','mci','dor'),
'limit'=> $results,
'order' => array(
'User.pe' => 'asc'
),
'recursive'=>-1
);
//run the paginate
$datas = $this->paginate('User');
//if the paginate is empty put in message. Then remove one of the variables in order first,last,pe,district,assigned
if(empty($datas))
{
$message = $message.'<br /><p> Search returned no results. Searching instead for:</p><p>';
if($first_empty == 0)
{
if(strlen($first_name_store) > 1)
{
$first_name = $first_name_store[0].'%';
$first_name_store = $first_name_store[0];
} else {
$first_name = '%';
$first_name_store = '';
}
} elseif($last_empty == 0) {
if(strlen($last_name_store) > 1)
{
$last_name = $last_name_store[0].'%';
$last_name_store = $last_name_store[0];
} else {
$last_name = '%';
$last_name_store = '';
}
} elseif($pe_empty == 0) {
$pe = '';
} elseif($ghq_empty == 0) {
$ghq = '';
} elseif($district_empty == 0) {
$district = '';
} elseif($rank_empty == 0) {
$rank = '';
} elseif(!empty($car)) {
$car = '';
} elseif(!empty($badge)) {
$badge = '';
}
}
}
$this->Session->write('User.inactive_store',$this->data['User']['inactive']);
$this->Session->write('User.pe_store',$this->data['User']['pe']);
$this->Session->write('User.district_store',$this->data['User']['district']);
$this->Session->write('User.ghq_store',$this->data['User']['ghq']);
$this->Session->write('User.last_name_store',$this->data['User']['last_name']);
$this->Session->write('User.first_name_store',$this->data['User']['first_name']);
$this->Session->write('User.rank_store',$this->data['User']['rank']);
$this->Session->write('User.status_store',$this->data['User']['status']);
$this->Session->write('User.race_store',$this->data['User']['race']);
$this->Session->write('User.sex_store',$this->data['User']['sex']);
$this->Session->write('User.type_store',$this->data['User']['type']);
$this->Session->write('User.results_store',$this->data['User']['results']);
$this->Session->write('User.psid_store',$this->data['User']['psid']);
$this->Session->write('User.psid_show_store',$this->data['User']['psid_show']);
$this->Session->write('User.radio_store',$this->data['User']['radio']);
$this->Session->write('User.unit_store',$this->data['User']['unit']);
$this->Session->write('User.card_number_store',$this->data['AirCard']['card_number']);
$this->Session->write('User.esn_store',$this->data['AirCard']['esn']);
$this->Session->write('User.ip_store',$this->data['AirCard']['ip_address']);
$this->set('pe',$pe);
$this->set('district',$district);
$this->set('ghq',$ghq);
$this->set('datas', $datas);
$this->set('message',$message);
$this->set('rank',$rank);
$this->set('psid',$psid);
$this->set('psid_show',$psid_show);
$results = 'true';
}
$this->set('results', $results);
View:
<?php
$html->addCrumb($user['User']['first_name'] . " " . $user['User']['last_name'], '/users');
?>
<?php echo $this->Html->script('jquery'); ?>
<!-- UNITBOOK index of users -->
<?php if($add == 1): ?>
<div style="color:white; background-color:black; padding-left:10px;">
<table>
<tr>
<td><div style="font-size: 40px; color:white; background-color:black; padding-left:10px;">Unitbook</div></td>
<td><div class = "mediumbuttons"><?php echo $this->Html->link('','/users/add/',array('class'=>'button_newuser')); ?></div></td>
</tr>
</table>
</div>
<?php else: ?>
<div style="height: 38px; color:white; background-color:black; padding-left:10px;">
<table>
<tr>
<td><div style="margin-top:7px; font-size: 40px; color:white; background-color:black; padding-left:10px;">Unitbook</div></td>
</tr>
</table>
</div>
<?php endif; ?>
<br />
<?php echo $form->create('User', array('action' => '/unitbook/'));?>
<fieldset class="ta_add_fieldset">
<legend class="ta_add_legend">
Search
</legend>
<table>
<tr>
<td>
<label class = "gi_label"><b>Last Name:</b></label>
</td>
<td>
<?php echo $this->Form->input('User.last_name',array('label' => ''));?>
</td>
<td>
<label class = "gi_label"><b>First Name:</b></label>
</td>
<td>
<?php echo $this->Form->input('User.first_name',array('label' => ''));?>
</td>
</tr>
<tr>
<td>
<label class = "gi_label"><b>PE:</b></label>
</td>
<td>
<?php echo $this->Form->input('User.pe',array('label' => '','size' => '10', 'maxlength' => '10'));?>
</td>
<td>
<label class = "gi_label"><b>Assigned To:</b></label>
</td>
<td>
<?php echo $form->select('User.district',$district_list);?>
</td>
<?php if($viewable): ?>
<td>
<label class = "gi_label"><b>Check to include inactive users</b></label>
</td>
<td>
<?php echo $this->Form->checkbox('User.inactive');?>
</td>
<?php endif; ?>
</tr>
</table>
<table>
<tr>
<td>
<label class = "gi_label"><b>Located At:</b></label>
</td>
<td>
<?php echo $form->select('User.ghq',$ghq_list);?>
</td>
</tr>
</table>
<table>
<tr>
<td>
<label class = "gi_label"><b>Rank:</b></label>
</td>
<td>
<?php echo $form->select('User.rank',$rank_list);?>
</td>
<td>
<label class = "gi_label"><b>Status:</b></label>
</td>
<td>
<?php echo $form->select('User.status',$status_list);?>
</td>
</tr>
</table>
<table>
<tr>
<td>
<label class = "gi_label"><b>Race:</b></label>
</td>
<td>
<?php echo $form->select('User.race',$race_list);?>
</td>
<td>
<label class = "gi_label"><b>Sex:</b></label>
</td>
<td>
<?php echo $form->select('User.sex',$sex_list);?>
</td>
<td>
<label class = "gi_label"><b>Type:</b></label>
</td>
<td>
<?php echo $form->select('User.type',$type_list);?>
</td>
</tr>
</table>
<table>
<tr>
<td>
<label class = "gi_label"><b>Car Number:</b></label>
</td>
<td>
<?php echo $this->Form->input('User.radio',array('label' => ''));?>
</td>
<td>
<label class = "gi_label"><b>Badge Number:</b></label>
</td>
<td>
<?php echo $this->Form->input('User.unit',array('label' => ''));?>
</td>
</tr>
</table>
<table>
<tr>
<td id='aggregatelabel'>
<label class="gi_label"><b>Results per page: </b></label>
</td>
<td>
<?php echo $this->Form->input('results', array('label' => '', 'options' => array(
'25' => '25',
'50' => '50',
'75' => '75',
'100' => '100',
'100000' => 'All'
))); ?>
</td>
<td>
<label class = "gi_label"><b>Public Safety ID:</b></label>
</td>
<td>
<?php echo $this->Form->input('User.psid',array('label' => ''));?>
</td>
<td>
<label class = "gi_label"><b>Only show users with Public Safety ID</b></label>
</td>
<td>
<?php echo $this->Form->checkbox('User.psid_show');?>
</td>
</table>
<?php if($mobile == 1): ?>
<table>
<tr>
<td>
<label class = "gi_label"><b>Air Card Number</b></label>
</td>
<td>
<?php echo $this->Form->input('AirCard.card_number',array('label' => ''));?>
</td>
<td>
<label class = "gi_label"><b>ESN</b></label>
</td>
<td>
<?php echo $this->Form->input('AirCard.esn',array('label' => ''));?>
</td>
<td>
<label class = "gi_label"><b>IP Address</b></label>
</td>
<td>
<?php echo $this->Form->input('AirCard.ip_address',array('label' => ''));?>
</td>
</tr>
</table>
<?php endif; ?>
<?php echo $form->submit('Search'); ?>
</fieldset>
<?php if($results == 'true'): ?>
<?php $limit = $this->params['paging']['User']['options']['limit'];
if($limit != 1): ?>
<fieldset class="ta_add_fieldset">
<legend class="ta_add_legend">
Results
</legend>
<?php echo $message; ?>
<div id="content">
<?php
$paginator->options(
array('update'=>'#content',
'evalScripts' => true,
'before' => $this->Js->get('#busy-indicator')->effect('fadeIn', array('buffer' => false)),
'complete' => $this->Js->get('#busy-indicator')->effect('fadeOut', array('buffer' => false)),
));
?>
<?php echo $this->Js->writeBuffer(); ?>
<?php echo $this->Html->image('http://ispspeis.isp.in.gov/Pictures/shield/logo/indicator.gif', array('id' => 'busy-indicator','class' => 'busy_float')); ?>
<table>
<tr>
<th><?php echo $paginator->sort('PE','pe');?></th>
<th><?php echo $paginator->sort('Name','last_name');?></th>
<th><?php echo $paginator->sort('Assigned To','district_id');?></th>
<th><?php echo $paginator->sort('Located At','ghq_id');?></th>
<th><?php echo $paginator->sort('Rank','rank_id');?></th>
</tr>
<?php foreach($datas as $data): ?>
<tr>
<td style="background-color: #FFFFFF; font-weight: bold; font-size:x-small;">
<?php echo $this->Html->link($data['User']['pe'],'/users/view/'.$data['User']['id']); ?>
</td>
<td style="background-color: #EEEEEE; font-weight: bold; font-size:x-small;">
<?php echo $this->Html->link($data['User']['last_name'].', '. $data['User']['first_name'].' '. $data['User']['middle_initial'],'/users/view/'.$data['User']['id']); ?>
</td>
<td style="background-color: #FFFFFF; font-weight: bold; font-size:x-small;">
<?php if(!empty($data['User']['district_id'])): echo $district_list[$data['User']['district_id']]; endif; ?>
</td>
<td style="background-color: #EEEEEE; font-weight: bold; font-size:x-small;">
<?php if(!empty($data['User']['ghq_id'])) :echo $ghq_list[$data['User']['ghq_id']]; endif; ?>
</td>
<td style="background-color: #FFFFFF; font-weight: bold; font-size:x-small;">
<?php if(!empty($data['User']['rank_id'])): echo $rank_list[$data['User']['rank_id']]; endif; ?>
</td>
<?php if($all == 1 || ($u_dist == 1 && $data['User']['district_id'] == $user['User']['district_id']) || ($u_div == 1 && $data['User']['ghq_id'] == $user['User']['ghq_id'])): ?>
<td>
<div class = "littlebuttons"><?php echo $this->Html->link('','/users/edit/'.$data['User']['id'],array('class'=>'button_edituser','title'=>'Edit User Information')); ?></div>
</td>
<?php endif; ?>
<td>
<div class = "littlebuttons"><?php echo $this->Html->link('','/users/printview/'.$data['User']['id'],array('class'=>'button_printer','title'=>'Print View')); ?></div>
</td>
<?php if($training == 1): ?>
<td>
<div class = "littlebuttons"><?php echo $this->Html->link('','/train_records/index/'.$data['User']['id'],array('class'=>'button_book','title'=>'Training Records')); ?></div>
</td>
<?php endif; ?>
<?php if($data['User']['sworn'] + $data['User']['cps'] + $data['User']['mci'] > 0): ?>
<?php if(($ta_all == 1) || ($ta_district == 1 && $data['User']['district_id'] == $user['User']['district_id']) || ($ta_division == 1 && $data['User']['ghq_id'] == $user['User']['ghq_id'])): ?>
<td>
<div class = "widelittlebuttons"><?php echo $this->Html->link('','/audits/index/'.$data['User']['id'],array('class'=>'button_microaudit','title'=>'Audit')); ?></div>
</td>
<td>
<div class = "littlebuttons"><?php echo $this->Html->link('','/trooper_activities/index/'.$data['User']['id'],array('class'=>'button_microactivity','title'=>'Trooper Activity')); ?></div>
</td>
<?php if($road == true): ?>
<td>
<div class = "littlebuttons"><?php echo $this->Html->link('','/settings/adjust_mile/'.$data['User']['id'],array('class'=>'button_road','title'=>'Mileage Update')); ?></div>
</td>
<?php endif; ?>
<?php endif; ?>
<?php else: ?>
<td>
<div class = "littlebuttons"><?php echo $this->Html->link('','/users/index/'.$data['User']['id'],array('class'=>'button_microcalendar','title'=>'Calendar')); ?></div>
</td>
<?php endif; ?>
<?php if($dor_view == 1 and !empty($dor_list[$data['User']['rank_id']])): ?>
<td>
<div class = "littlebuttons"><?php echo $this->Html->link('','/ftos/index/'.$data['User']['id'],array('class'=>'button_fto','title'=>'Daily Observation Records')); ?></div>
</td>
<?php endif; ?>
<?php if($mobile == 1): ?>
<td>
<div class = "littlebuttons"><?php echo $this->Html->link('','/air_cards/index/'.$data['User']['id'],array('class'=>'button_micromobile','title'=>'Mobile Records')); ?></div>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</table>
<?php echo $this->Paginator->numbers(); ?>
<?php echo $this->Paginator->prev('< Previous', null, null, array('class' => 'disabled')); ?>
<?php echo $this->Paginator->next('Next >', null, null, array('class' => 'disabled')); ?>
<?php echo $this->Paginator->counter(array(
'format' => 'Page %page% of %pages%, showing %start% - %end% records out of
%count% total'
)); ?>
<?php echo $this->Html->link('Export','/users/export_xls'); ?>
</div>
</fieldset>
<?php endif; ?>
<?php endif; ?>
<?php echo $form->end(); ?>
<?php echo $this->Js->writeBuffer(); ?>
Any help is greatly appreciated!

IE does wierd things with Ajax and caching. added the following to the page to force it to actually load each time:
<script>
$.ajaxSetup({ cache: false });
</script>

Related

How insert array to database in open cart?

I build dynamic input by add row table, and user input by autocomplete, then I store PRODUCT_ID in <input name="idp" value="">
E.g User input twice times (HP & Computer)
Name Product | PRODUCT_ID
HP = 2945
COMPUTER = 8654
Should be in array is = (2945,8654)
This is for Controller:
class ControllerItemItem extends Controller { //Controller/Item/Item.php
private $error = array();
public function index() {
$this->language->load('item/item');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('item/item');
$this->getList();
}
protected function getList(){
if (isset($this->request->get['head_text_field'])){
$head_text_field = $this->request->get['head_text_field'];
} else {
$head_text_field = null;
}
if (isset($this->request->get['title_text_field'])){
$title_text_field = $this->request->get['title_text_field'];
} else {
$title_text_field = null;
}
if (isset($this->request->get['max'])){
$max = $this->request->get['max'];
} else {
$max = null;
}
if(isset($this->request->get['idp'])){
$product = $this->request->get['idp'];
$product2 = array();
foreach($product as $p)
{
$product2[] = $p;
}
}else {
$product = null;
}
// BREADCRUMBS //
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('module/item', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
// END //
// Call Language //
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['entry_head'] = $this->language->get('entry_head');
$this->data['entry_title'] = $this->language->get('entry_title');
$this->data['entry_product'] = $this->language->get('entry_product');
$this->data['entry_max_item'] = $this->language->get('entry_max_item');
$this->data['button_save'] = $this->language->get('button_save');
$this->data['button_cancel'] = $this->language->get('button_cancel');
// END //
$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
$this->data['action'] = $this->url->link('item/item/insert', 'token=' . $this->session->data['token'], 'SSL');
$this->data['token'] = $this->session->data['token'];
$data = array(
'head_text_field' => $head_text_field,
'title_text_field' => $title_text_field,
'max' => $max
);
$this->template = 'item/item.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
public function insert()
{
$this->language->load('item/item');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('item/item');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
//$this->model_item_item->insert_head($this->request->post);
$this->model_item_item->insert_detail($this->request->post);
//$this->session->data['success'] = $this->language->get('text_success');
//$this->redirect($this->url->link('item/item', 'token=' . $this->session->data['token'], 'SSL'));
}
}
protected function validateForm() {
if (!$this->user->hasPermission('modify', 'item/item')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if ((utf8_strlen($this->request->post['head_text_field']) < 1) || (utf8_strlen($this->request->post['head_text_field']) > 64)) {
$this->error['head'] = $this->language->get('error_head');
}
if (!$this->request->post['title_text_field']) {
$this->error['title'] = $this->language->get('error_title');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
This is for Model :
class ModelItemItem extends Model {
public function insert_head($data)
{
$this->db->query("INSERT INTO " . DB_PREFIX . "show_product SET head_text = '" . $this->db->escape($data['head_text_field']) . "', title_text = '" . $this->db->escape($data['title_text_field']) . "', max_item = '" . $this->db->escape($data['max']) . "'");
}
public function insert_detail($product2)
{
foreach($product2 as $detail)
{
//$this->db->query("INSERT INTO " . DB_PREFIX . "show_product_detail SET product_id = '". $this->db->escape($detail['product']) . "'");
}
echo $detail[0];
}
}
This is for view :
<?php echo $header; ?>
<div id="content">
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><?php echo $breadcrumb['text']; ?>
<?php } ?>
</div>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<?php if ($success) { ?>
<div class="success"><?php echo $success; ?></div>
<?php } ?>
<div class="box">
<div class="heading">
<h1><img src="view/image/product.png" alt="" /> <?php echo $heading_title; ?></h1>
<div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><?php echo $button_cancel; ?></div>
</div>
<div class="content">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
<table class="form">
<tr>
<td><span class="required">*</span> <?php echo $entry_head; ?></td>
<td><input type="text" name="head_text_field" value="" placeholder="Input Head Text" size="40"/>
<?php if ($error_head) { ?>
<span class="error"><?php echo $error_head; ?></span>
<?php } ?>
</td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_title; ?></td>
<td><textarea name="title_text_field" placeholder="Input Title Text" style="width:230px;"/></textarea>
<?php if ($error_title) { ?>
<span class="error"><?php echo $error_title; ?></span>
<?php } ?>
</td>
</tr>
<tr>
<td><?php echo $entry_max_item; ?></td>
<td>
<select name="max" id="maxitem">
<?php
for($i=1; $i<=6; $i++)
{
if($i == 1)
echo "<option selected='selected' value=".$i.">".$i."</option>";
else
echo "<option value=".$i.">".$i."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td><?php echo $entry_product; ?></td>
<td><input type="text" id="product" name="product" value="" placeholder="Input Product" size="40"/></td>
<td><input type="hidden" id="idp" name="idp" value="" /></td>
</tr>
<tr>
<td></td>
<td>
<table>
<tr>
<td><input type="button" id="ADD" value="Add Item"></td>
<td><input type="reset" id="RESET" value="Reset"></td>
</tr>
</table>
</td>
</tr>
<tr>
</tr>
</table>
<table border="1" id="tblname" cellpadding="5" cellspacing="5">
<thead>
<tr>
<td>
Total Item
</td>
<td>
Id Item
</td>
<td>
Name Item
</td>
<td>
DELETE
</td>
<tr>
</thead>
<tbody align="center">
</tbody>
</table>
</form>
</div>
</div>
</div>
<script type="text/javascript"><!--
$('input[name=\'product\']').autocomplete({
delay: 100,
source: function(request, response) {
$.ajax({
url: 'index.php?route=catalog/product/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent(request.term),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
label: item.name,
value: item.product_id
}
}));
}
});
},
select: function(event, ui) {
$('input[name=\'product\']').val(ui.item.label);
$('input[name=\'idp\']').val(ui.item.value);
return false;
},
focus: function(event, ui) {
return false;
}
});
//--></script>
<Script type="text/javascript">
$(document).ready(function(){
var item = 1;
var isAllowed = 3;
var isSet = 0;
$('#ADD').click(function(){
var maxitem = parseInt($("#maxitem").val(), 10); //from max item in html
var iCount = 0;
if($('#product').val()){ // check input product
if( item <= maxitem )
{
iCount = $('#tblname tbody tr').length + 1;
szTr = "<tr><td>";
szTr = szTr + iCount + "</td>";
szTr = szTr + "<td>" +$('#idp').val() +"</td>";
szTr = szTr + "<td>" +$('#product').val() +"</td>";
szTr = szTr + "<td><input type='button' class='DEL' value='DELETE'></td>";
szTr = szTr + "</tr>";
$('#tblname tbody').append(szTr);
item +=1;
isSet = 1;
restFormOpts();
}
else
{
alert ("Max Limit !!!");
}
}else{alert('Enter Product !!! ');}
});
// for delete row
$('body').on('click','#RESET', function() {
item = 1;
isAllowed = 3;
isSet = 0;
$("#maxitem").attr("disabled",false);
$('.DEL').parents('tr').remove();
});
$('body').on('click', 'input.DEL', function() {
$(this).parents('tr').remove();
item -= 1;
});
function restFormOpts()
{
if(isSet === isAllowed) {
$("#ADD").attr("disabled",true);
$("#maxitem").attr("disabled",false);
}
else {
$("#ADD").attr("disabled",false);
$("#maxitem").attr("disabled",true);
}
}
});
</script>
<?php echo $footer; ?>
When I try insert query to my database, value only 1 number.
Then I try Echo for make sure variable is correct but it's wrong, the result is the last user input (Computer, in array(8,6,5,4))? it's should be (2945,8654) not (8,6,5,4)?
Can some one help me for fix this?? I already try fix this problem for 1 week still no hope :(
If you want to insert array variables in database, First you need encode them and then insert them .
Ex. $abc = array(3,45,6,78,89) ;
Query : "INSERT INTO " . DB_PREFIX . "show_product_detail SET product_id = '". $this->db->escape(json_encode($abc)) . "'

How to correctly move CakePHP tree items up and and down?

Im stuck with moving items of a tree up and down, the item is not being moved to the correct position.
Please check these pictures:
https://docs.google.com/a/wgs.co.id/file/d/0B88jB6a4wxkTdTNtTGl1YjhXdTQ/edit?usp=drivesdk
https://docs.google.com/a/wgs.co.id/file/d/0B88jB6a4wxkTcW5pSFJyUnVhejA/edit?usp=drivesdk
My code for moving items is based on http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::moveDown
Here is my code:
Controller
function admin_moveup($id = null, $delta = null) {
$this->ProductNeed->id = $id;
if (!$this->ProductNeed->exists()) {
throw new NotFoundException(__('Invalid id'));
}
if ($delta > 0) {
$this->ProductNeed->moveUp($this->ProductNeed->id, abs($delta));
} else {
$this->Session->setFlash(
'Silahkan tentukan posisi nomor order terlebih dahulu'
);
}
return $this->redirect(array('admin' => true, 'controller' => $this->params['controller'], 'action' => 'index'));
}
function admin_movedown($id = null, $delta = null) {
$this->ProductNeed->id = $id;
if (!$this->ProductNeed->exists()) {
throw new NotFoundException(__('Invalid id'));
}
if ($delta > 0) {
$this->ProductNeed->moveDown($this->ProductNeed->id, abs($delta));
} else {
$this->Session->setFlash(
'Silahkan tentukan posisi nomor order terlebih dahulu'
);
}
return $this->redirect(array('admin' => true, 'controller' => $this->params['controller'], 'action' => 'index'));
}
View
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Order</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
if(!empty($data['rows'])) {
$i = 0;
foreach($data['rows'] as $key => $value) {
$i++;
?>
<tr id="row-<?php echo $i; ?>">
<td><?php echo $i; ?></td>
<td><?= $value ?></td>
<td>
<?php
echo $this->Html->link(
'Up',
'/admin/'.$this->params['controller'].'/moveup/'.$key.'/'.$i
);
?>
<?php
echo $this->Html->link(
'Down',
'/admin/'.$this->params['controller'].'/movedown/'.$key.'/'.$i
);
?>
</td>
<td>
<ul class="action">
<li><i class="glyphicon glyphicon-edit" data-toggle="tooltip" title="Ubah"></i></li>
<li><i class="glyphicon glyphicon-ban-circle" data-toggle="tooltip" title="Hapus"></i></li>
</ul>
<?= $html->modalBoxDelete($i, $key) ?>
</td>
</tr>
<?php
}
} else {
echo $html->noData(4);
}
?>
</tbody>
</table>
Re-read the docs that you've linked, the code takes a delta value, ie the numer of positions the item should be moved.
If you'd wanted to move an item by just one row, then you'll have to use a delta of 1, your view template code however passes the items index in the array as the delta value, so for the Kesehan Mata row in your example that would be a 4, hence the item is moved to after Stamina Vitalitas, which is 4 top level items ahead.
So either pass a static value of 1, like
'/admin/'.$this->params['controller'].'/moveup/'.$key.'/1'
'/admin/'.$this->params['controller'].'/movedown/'.$key.'/1'
or if you don't plan to ever move the items by more than 1, simply remove the delta argument alltogether and hardcode the value passed to TreeBehavior::up/down() in your controller methods.

Delete multiple rows by ticking Checkbox

How do I delete multiple rows by checking a checkbox?
I have a table of records, and I'd like to to delete multiple rows at once.
This is my my deleteselected function:
UPDATED
public function order() {
if(!empty($this->data)) {
//If at lesst 1 check box is selected
if (isset($this->data) && !empty($this->data['order_id'])) {
$selectedReferences = $this->data['order_id'];
$flagReferenceAdded = false;
foreach ($selectedReferences as $singleReference) {
//NEW DELETE
$this->Order->id = $singleReference;
$this->Order->delete();
//NEW DELETE
}
//After delete
$this->Session->setFlash(
__('Your All record Are deleted.')
);
return $this->redirect(array(''));
}
else{
echo "Select at least 1 ORDER.";
}
}
and in my view.
<?php
echo $this->Form->create('Order',array('url' => array('controller' => 'admin', 'action' => 'order'))); ?>
<table class="table table-bordered table-hover">
<th>Name</th>
<th>Email</th>
<th>phone</th>
<th>view</th>
<th>delete</th>
<thead>
</tr>
</thead>
<tbody>
<?php foreach ($order as $orders): ?>
<tr>
<td><?php echo $orders['Order']['varfullname']; ?></td>
<td><?php echo $orders['Order']['varemailid']; ?></td>
<td><?php echo $orders['Order']['varphone']; ?></td>
<td>
<?php echo $this->Html->link('',
array('controller' => 'orders', 'action' => 'view', $orders['Order']['id']), array('title'=>'VIEW','class' => 'fa fa-search'));?>
</td>
<td><input type="checkbox" name="order_id[]" value ="<?php echo $orders['Order']['id'];?>" hiddenField = "false">
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</br>
<?
echo $this->Form->end('Deleteselected'); ?>
</div>
</div>
</br>
</div>
<!-- /.row -->
after using below answer my delete selected working fine
Use in ctp
//in ctp Along with EACH record use Checkbox integration . Dont use Checkbox code u used.
<input type="checkbox" name="order_id[]" value ="<?php echo $referenceSingle['Order']['id'];?>" hiddenField = "false">
//In controller
if(!empty($this->data)) {
//If at lesst 1 check box is selected
if (isset($this->data) && !empty($this->data['order_id'])) {
$selectedReferences = $this->data['order_id'];
$flagReferenceAdded = false;
foreach ($selectedReferences as $singleReference) {
//NEW DELETE
$this->Order->id = $singleReference;
$this->Order->delete();
//NEW DELETE
}
//After delete
$this->Session->setFlash(
__('Your All record Are deleted.')
);
return $this->redirect(array(''));
}
else{
echo "Select at least 1 ORDER.";
}
}
UPDATE
Use Above Code in your Index method itself ,Dont create deleteAll method.
OR
Make <form action TO deleteAll
LIKE
echo $this->Form->create('searchCourse',array('url' => array('controller' => 'Courses', 'action' => 'index')));
UPDATE
For proper Workflow refer :
ALWAYS do paperwork and Algorithm ,Before Coding SIR.

Sort from low to high using wordpress review widget

Need some help getting widget to sort the reviews from low to high. I know this is reverse of the norm, but this website focuses on how "bad" something is. The website is here: http://designtatics.fatcow.com/Badkickstarter/ it's the second tab down called top 3. Excuse the mess, still a work in progress.
// order by rating?
if (isset($order) && $order == 'rating') {
$query_args['orderby'] = 'meta_value';
}
else {
$query_args['orderby'] = 'date';
}
$r = new WP_Query($query_args);
I've already tried adding $query_args['order'] = 'ASC'; with no luck. This is all new to me so the more specific the better. Thanks!
UPDATE: I think I was trying to modify the wrong widget, heres the new code:
<?php
class Bunyad_TabbedRecent_Widget extends WP_Widget
{
public function __construct()
{
parent::__construct(
'bunyad-tabbed-recent-widget',
'Bunyad - Recent Tabs',
array('description' => __('Tabs: Recent, category1, category2...', 'bunyad-widgets'), 'classname' => 'tabbed')
);
add_action('save_post', array($this, 'flush_widget_cache'));
add_action('deleted_post', array($this, 'flush_widget_cache'));
add_action('switch_theme', array($this, 'flush_widget_cache'));
// init hook
add_action('init', array($this, 'init'));
}
public function init()
{
// only in admin cp for form
if (is_admin()) {
wp_enqueue_script('widget-tabs', plugins_url('/bunyad-widgets/js/widget-tabs.js'));
}
}
// #todo wrap existing widgets with in-memory cache
public function widget($args, $instance)
{
global $post; // setup_postdata not enough
// set defaults
$titles = $cats = $tax_tags = array();
extract($args);
extract($instance);
// missing data?
if (!count($titles) OR !count($cats)) {
_e('Recent tabs widget still need to be configured! Add tabs, add a title, and select type for each tab in widgets area.', 'bunyad-widgets');
return;
}
$tabs = array();
foreach ($titles as $key => $title) {
// defaults missing?
if (empty($tax_tags[$key])) {
$tax_tags[$key] = '';
}
if (empty($cats[$key])) {
$cats[$key] = '';
}
$tabs[$title] = array('cat_type' => $cats[$key], 'tag' => $tax_tags[$key]);
}
// latest posts
$posts = $this->get_posts($tabs, $number);
?>
<?php echo $before_widget; ?>
<ul class="tabs-list">
<?php
$count = 0;
foreach ($posts as $key => $val): $count++; $active = ($count == 1 ? 'active' : '');
?>
<li class="<?php echo $active;?>">
<?php echo $key; ?>
</li>
<?php endforeach; ?>
</ul>
<div class="tabs-data">
<?php
$i = 0;
foreach ($posts as $tab => $tab_posts): $i++; $active = ($i == 1 ? 'active' : ''); ?>
<ul class="tab-posts <?php echo $active; ?> posts-list" id="recent-tab-<?php echo esc_attr($i); ?>">
<?php if ($tabs[$tab] == 'comments'): ?>
<?php
foreach ($tab_posts as $comment):
?>
<li class="comment">
<span class="author"><?php printf('%s said', get_comment_author_link($comment->comment_ID)); ?></span>
<p class="text"><?php comment_excerpt($comment->comment_ID); ?></p>
<?php echo get_the_title($comment->comment_post_ID); ?>
</li>
<?php
endforeach;
?>
<?php else: ?>
<?php foreach ($tab_posts as $post): setup_postdata($post); ?>
<li>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail('post-thumbnail', array('title' => strip_tags(get_the_title()))); ?>
<?php if (class_exists('Bunyad') && Bunyad::options()->review_show_widgets): ?>
<?php echo apply_filters('bunyad_review_main_snippet', ''); ?>
<?php endif; ?>
</a>
<div class="content">
<time datetime="<?php echo get_the_date('Y-m-d\TH:i:sP'); ?>"><?php echo get_the_date(); ?> </time>
<span class="comments"><a href="<?php echo esc_attr(get_comments_link()); ?>"><i class="fa fa-comments-o"></i>
<?php echo get_comments_number(); ?></a></span>
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>">
<?php if (get_the_title()) the_title(); else the_ID(); ?></a>
</div>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
<?php endforeach; ?>
</div>
<?php echo $after_widget; ?>
<?php
wp_reset_postdata();
}
public function get_posts($tabs, $number)
{
// posts available in cache? - use instance id to suffix
$cache = get_transient('bunyad_tabbed_recent_posts');
if (is_array($cache) && isset($cache[$this->number])) {
return $cache[$this->number];
}
// get posts
$args = array('numberposts' => $number, 'ignore_sticky_posts' => 1);
foreach ($tabs as $key => $val) {
$opts = array();
switch ($val['cat_type']) {
case 'popular':
$opts['orderby'] = 'comment_count';
break;
case 'comments':
$posts[$key] = get_comments(array('number'=> $number, 'status' => 'approve'));
continue 2; // jump switch and foreach loop
case 'top-reviews':
// get top rated of all time
$opts = array_merge($opts, array('orderby' => 'meta_value', 'meta_key' => '_bunyad_review_overall'));
break;
case 'recent':
break;
case 'tag':
$opts['tag'] = $val['tag'];
break;
default:
$opts['cat'] = intval($val['cat_type']);
break;
}
//$query = new WP_Query(array_merge($args, $opts));
$posts[$key] = get_posts(array_merge($args, $opts));
}
if (!is_array($cache)) {
$cache = array();
}
$cache[ $this->number ] = $posts;
set_transient('bunyad_tabbed_recent_posts', $cache, 60*60*24*30); // 30 days transient cache
return $posts;
}
public function flush_widget_cache()
{
delete_transient('bunyad_tabbed_recent_posts');
}
public function update($new, $old)
{
// fix categories
foreach ($new['cats'] as $key => $cat) {
$new['cats'][$key] = strip_tags($cat);
}
foreach ($new['titles'] as $key => $title) {
$new['titles'][$key] = strip_tags($title);
}
foreach ($new['tax_tags'] as $key => $tag) {
$new['tax_tags'][$key] = trim(strip_tags($tag));
}
$new['number'] = intval($new['number']);
// delete cache
$this->flush_widget_cache();
return $new;
}
public function form($instance)
{
$instance = array_merge(array('titles' => array(), 'cats' => array(0), 'number' => 4, 'cat' => 0, 'tax_tags' => array()), $instance);
extract($instance);
?>
<style>
.widget-content p.separator { padding-top: 10px; border-top: 1px solid #d8d8d8; }
.widget-content .tax_tag { display: none; }
</style>
<div id="tab-options">
<script type="text/html" class="template-tab-options">
<p class="title separator">
<label><?php printf(__('Tab #%s Title:', 'bunyad-widgets'), '<span>%n%</span>'); ?></label>
<input class="widefat" name="<?php
echo esc_attr($this->get_field_name('titles')); ?>[%n%]" type="text" value="%title%" />
</p>
<div class="cat">
<label><?php printf(__('Tab #%s Category:', 'bunyad-widgets'), '<span>%n%</span>'); ?></label>
<?php
$r = array('orderby' => 'name', 'hierarchical' => 1, 'selected' => $cat, 'show_count' => 0);
// categories list
$cats_list = walk_category_dropdown_tree(get_terms('category', $r), 0, $r);
// custom options
$options = array(
'recent' => __('Recent Posts', 'bunyad-widgets'),
'popular' => __('Popular Posts', 'bunyad-widgets'),
'top-reviews' => __('Top Reviews', 'bunyad-widgets'),
'tag' => __('Use a Tag', 'bunyad-widgets'),
);
?>
<select name="<?php echo $this->get_field_name('cats') .'[%n%]'; ?>">
<?php foreach ($options as $key => $val): ?>
<option value="<?php echo esc_attr($key); ?>"<?php echo ($cat == $key ? ' selected' : ''); ?>><?php echo esc_html($val); ?></option>
<?php endforeach; ?>
<optgroup label="<?php _e('Category', 'bunyad-widgets'); ?>">
<?php echo $cats_list; ?>
</optgroup>
</select>
<div class="tax_tag">
<p><label><?php printf(__('Tab #%s Tag:', 'bunyad-widgets'), '<span>%n%</span>'); ?></label> <input type="text" name="<?php
echo esc_attr($this->get_field_name('tax_tags')); ?>[%n%]" value="%tax_tag%" /></p>
</div>
<p>[x] <?php _e('remove', 'bunyad-widgets'); ?></p>
</div>
</script>
<p class="separator"><?php _e('Add More Tabs', 'bunyad-widgets'); ?></p>
<?php
if (is_integer($this->number)): // create for valid instances only
foreach ($cats as $n => $cat):
?>
<script>
jQuery(function($) {
$('.widget-liquid-right [id$="bunyad-tabbed-recent-widget-'+ <?php echo $this->number; ?> +'"] #add-more-tabs').trigger(
'click',
[{
'n': <?php echo ($n+1); ?>,
'title': '<?php echo esc_attr($titles[$n]); ?>',
'selected': '<?php echo esc_attr($cat); ?>',
'tax_tag': '<?php echo esc_attr($tax_tags[$n]); ?>'
}]);
});
</script>
<?php
endforeach;
endif;
?>
</div>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts in each tab:', 'bunyad-widgets'); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" />
</p>
<?php
}
}

CakePHP table sorting with bootstrap icons

I want to sort a table by id when clicking on it. It is working but the main thing is that the bootstrap arrow up and down icons should also be attached to the id label.
When the data is displayed in descending order, then the bootstrap arrow-bottom icon should be shown, and when the data is displayed in ascending order, then the arrow-up icon should be shown.
UsersController.php
public $paginate = array('limit'=>4);
public function index() {
$this->User->recursive = 0;
$this->set('users', $this->paginate());
}
index.ctp
<div class="users index">
<h2><?php echo __('Users'); ?></h2>
<table class="zebra-striped table-bordered " cellpadding="0" cellspacing="0">
<tr>
<th>
<a href='' >
<?php echo $this->Paginator->sort('id'); ?>
<i class='icon-arrow-up'></i>
</a>
</th>
<th><a href='' >First Name <i class='icon-arrow-down'></i>
</a> </th>
<th>Last Name <i class='icon-resize-full'></i></a></th>
</tr>
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo h($user['User']['id']); ?> </td>
<td><?php echo h($user['User']['first_name']); ?> </td>
<td><?php echo h($user['User']['last_name']); ?> </td>
</tr>
<?php endforeach; ?>
</table>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
));
?> </p>
<div>
<div class="pagination">
<ul>
<?php
echo $this->Paginator->prev(__('prev'), array('tag' => 'li'),
null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a'));
echo $this->Paginator->numbers(array('separator' => '','currentTag'
=> 'a', 'currentClass' => 'active','tag' => 'li','first' => 1));
echo $this->Paginator->next(__('next'), array('tag' => 'li','currentClass' => 'disabled'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a'));
?>
</ul>
</div>
A Simple Solution using Jquery, just add the below 3 lines in your default application.js or in layout/default.ctp
$('th a').append(' <i class="icon-sort"></i>');
$('th a.asc i').attr('class', 'icon-sort-down');
$('th a.desc i').attr('class', 'icon-sort-up');
Another Simple CSS Based Solution, Include Font Awesome's necessary files.
th > a:after {
content: " \f0dc";
font-family: FontAwesome;
}
th > a.asc:after {
content: " \f0dd";
font-family: FontAwesome;
}
th > a.desc:after {
content: " \f0de";
font-family: FontAwesome;
}
Use PaginatorHelper::sortDir() to check the current sort direction and build the class name based on that value:
<i class='icon-arrow-<?php echo $this->Paginator->sortDir() === 'asc' ? 'up' : 'down'; ?>'></i>
To embed this into a sort link, pass the HTML as the second parameter to PaginatorHelper::sort(), and set the escape option to false:
$type = $this->Paginator->sortDir() === 'asc' ? 'up' : 'down';
$icon = "<i class='icon-arrow-" . $type . "'></i>";
echo $this->Paginator->sort('id', $icon, array('escape' => false));
That should result in a link like:
<i class='icon-arrow-up'></i>
You need also check a key, so it would be
<?php echo $this->Paginator->sort('title', 'My great title'); ?>
<?php if ($this->Paginator->sortKey() == 'title'): ?>
<i class='fa fa-sort-<?php echo $this->Paginator->sortDir() === 'asc' ? 'up' : 'down'; ?>'></i>
<?php else: ?>
<i class='fa fa-sort'></i>
<?php endif; ?>

Resources