How implement multiple editable column with yii-booster? - php

Am working on a Yii staff-hours scheduling project, stuck on editable-curd-staffhours-module. I want to store staff scheduling hours in StaffHourstable using Editable Yii Booster Extension.
My staffhours table DB stucture as:
id(pk) user_id(fk) staff_id(int) monday(text) tuesday(text) wednesday(text) thursday(text) friday(text) saturday(text) sunday(text)
All day-text fields used to store serialize time as in associative-array format:
array(
'12:00 AM' => 'open',
'12:30 AM' => 'close',
'01:00 AM' => 'close',
'01:30 AM' => 'open',
'02:00 AM' => 'open',
.
.
.
'11:00 PM' => 'close'
'11:30 PM' => 'close'
);
I have implemented Editable UI using Yii Booster Extension, watch snap below:
Problem is that am unable to recognize how to store/update staff-hours data in DB.
Some Of Code i have done
---- In View ----
<?php
$this->breadcrumbs=array(
'Settings'=>array('settings/settings'),
'Staff Hours',
);
$user_id = Yii::app()->user->getId();
$condition = "user_id = '$user_id'";
$data = StaffHours::model()->findAll();
$Monday = unserialize($data[0]['monday']);
$Tuesday = unserialize($data[0]['tuesday']);
$Wednesday = unserialize($data[0]['wednesday']);
$Thursday = unserialize($data[0]['thursday']);
$Friday = unserialize($data[0]['friday']);
$Saturday = unserialize($data[0]['saturday']);
$Sunday = unserialize($data[0]['sunday']);
foreach($data as $data)
{
?>
<div id="settinghead">StaffS Hours </div>
<div id="leftmenu"> <?php $this->widget('application.components.widgets.SettingsMenu.settingsmenuWidget'); ?></div>
<div id="rightcontent">
<div id="pageheding">Staff Hours Detail </div>
<table class="items table table-bordered">
<thead>
<tr><th scope="col">Time</th> <th scope="col">Monday</th> <th scope="col">Tuesday</th><th scope="col">Wednesday</th>
<th scope="col">Thursday</th><th scope="col">Friday</th><th scope="col">Saturday</th><th scope="col">Sunday</th> </tr>
</thead>
<?php
$start = strtotime('12:00am');
$end = strtotime('11:59pm');
for( $i = $start; $i <= $end; $i += 900)
{
$time = date('h:i A', $i);
?>
<tr>
<th scope="row"><?php echo $time; ?></th>
<td id="mon<?php echo $time; ?>">
<?php
$this->widget('bootstrap.widgets.TbEditableField', array(
'type' => 'select',
'model' => $data,
'emptytext' => $Monday[$time],
'attribute' => 'monday',
'url' => $this->createUrl('staffhours/updatetime&time='.$time), //url for submit data
'source' => array('Open', 'Close', 'Away'),
'value' => $time,
'enabled' => true
));
?>
</td>
<td id="tue<?php echo date('g:i A', $i); ?>"><?php echo $Tuesday[$time]; ?></td>
<td id="wed<?php echo date('g:i A', $i); ?>"><?php echo $Wednesday[$time]; ?></td>
<td id="thu<?php echo date('g:i A', $i); ?>"><?php echo $Thursday[$time]; ?></td>
<td id="fri<?php echo date('g:i A', $i); ?>"><?php echo $Friday[$time]; ?></td>
<td id="sat<?php echo date('g:i A', $i); ?>"><?php echo $Saturday[$time]; ?></td>
<td id="sun<?php echo date('g:i A', $i); ?>"><?php echo $Sunday[$time]; ?></td>
</tr>
<?php
}
}
?>
</table>
</div>
---- In StaffHoursController Controller ----
/**
* Update time.
*/
public function actionUpdatetime($time)
{
$user_id = Yii::app()->user->getId();
$pk = $_POST['pk'];
$day = $_POST['name'];
$status = $_POST['value'];
$GetData = StaffHours::model()->findByPk($pk);
$DayTimes = unserialize($GetData->monday);
if(array_key_exists($time, $DayTimes))
{
unset($DayTimes[$time]);
//merge new value
$DayTimes[$time] = $status;
array_push($DayTimes, $DayTimes[$time]);
$attributes = array($day => serialize($DayTimes));
$condition = "id = '$pk' AND user_id = '$user_id'";
StaffHours::model()->updateByPk($pk, $attributes, $condition);
}
}
If am going wrong or another easy way available to staff hours using Editable-UI.
Then please suggest a better way to store Staff-Hours using Editable-UI.

I believe storing array data into MySql text column is very impractical, since you will loose performance, ability to implement proper searching technique and etc. A better database design can be:
Each staff has many hours, and each hour can be assigned to many staff, a simple MANY_MANY relationship.
The advantage is that you can search for any date, any hour, any staff with a very easy,simple, singe query, or ActiveRecord:

Related

Pagination for a table in yii

I'm using Yii application. In that how to give pagination to a table contents( not using cgridview).
config/main.php
'params'=>array(
'adminEmail'=>'webmaster#example.com',
'listPerPage'=> 10,//default pagination size
),
In Controller,
public function actionOutbox() {
$criteria = new CDbCriteria;
$criteria->condition = 'from_userid = :id';
$criteria->order = 'time DESC';
$criteria->params = array (':id'=>Yii::app()->user->id);
$item_count = Email::model()->count($criteria);
$model = Email::model()->findAll($criteria);
$pages = new CPagination($item_count);
$pages->setPageSize(Yii::app()->params['listPerPage']);
$pages->applyLimit($criteria);
$this->render('outbox', array(
'model' => $model,
'item_count'=>$item_count,
'page_size'=>Yii::app()->params['listPerPage'],
'items_count'=>$item_count,
'pages'=>$pages,
));
}
In View,
<table data-provides="rowlink" data-page-size="20" data-filter="#mailbox_search" class="table toggle-square default footable-loaded footable" id="mailbox_table">
<thead>
<tr>
<th></th>
<th data-hide="phone,tablet">To</th>
<th>Subject</th>
<th data-hide="phone" class="footable-last-column">Date</th>
</tr>
</thead>
<tbody>
<?php
foreach ($model as $item) {
if ($item->email_status == 1)
echo '<tr id="' . $item->emailid . '" class="unreaded rowlink" style="display: table-row;">';
else
echo '<tr id="' . $item->emailid . '" class="rowlink" style="display: table-row;">';
echo '<td class="nolink footable-first-column">';
echo '<span class="footable-toggle"></span>';
echo '</span></td>';
echo '<td>' . $item->touser->username . '</td>';
echo '<td>' . $item->email_subject . '</td>';
$originalDate = $item->time;
$newDate = date("Y-M-d H:i:s", strtotime($originalDate));
echo '<td class="footable-last-column">' . $newDate . '</td></tr>';
}
?>
</tbody>
</table>
<?php
$this->widget('CLinkPager', array(
'currentPage' => $pages->getCurrentPage(),
'itemCount' => $item_count,
'pageSize'=> $page_size,
'maxButtonCount' => 5,
//'nextPageLabel' =>'My text >',
'htmlOptions' => array('class'=>'pages'),
));
?>
By using this code current page size is not working. Full values from table are displayed. I changed page size from 10 to 2 also, but not working.
What am I doing wrong?
Please help me. Thanks in advance
You use findAll without limit and want that yii understand about pagination?
Use CGridView widget instead it and set pagination in DataProvider (not create separate object of pagination: it not affort to result count).
And please read this topic.
Thanks.

Click on link in tab but link on second tab is activated

I created a web page with two tabs, each page having a list of links. When I click on a link on first tab, the link on the second tab is activated. That is unless its a row number that exceeds the number of rows on the second tab. The output HTML is correct. Both tabs by themselves work fine.
I am using Yii 1.1.14, php 5.4.11
Controller Action:
public function actionTest5() {
$fileNew = new File;
$criteria = new CDbCriteria;
$criteria->select='id,name,description';
$criteria->condition='t.user_id='.(int)Yii::app()->user->id;;
$criteria->order='t.date_updated desc, t.date_entered desc';
$criteria->limit=5;
$templateList=File::model()->findAll($criteria);
$criteria = new CDbCriteria;
$criteria->select='id,name,description';
$criteria->condition='t.user_id='.(int)Yii::app()->user->id;;
$criteria->order='t.date_updated desc, t.date_entered desc';
$criteria->limit=3;
$listFile= Listfile::model()->findAll($criteria);
$docI = new Document;
$fileNew = new File;
$url = Yii::app()->createUrl('test/setup');
if(isset($_POST['File']) OR isset($_POST['Document']))
$this->redirect($url);
$this->render('test5', array(
'model'=>$docI,
'templateList'=>$templateList,
'listFile'=>$listFile,
'fileNew'=>$fileNew,
));
}
View File test5:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'setup-form',
'enableClientValidation'=>true,
));
$tabArray=array();
$tabArray["Tab1"] = array(
'id'=>'1',
'content'=>$this->renderPartial('_testTab1',
array(
'tabNum'=>1,
'form'=>$form,
'model'=>$model,
'templateList'=>$templateList,
),TRUE));
$tabArray["Tab2"] = array(
'id'=>'2',
'content'=>$this->renderPartial('_testTab2',
array(
'tabNum'=>2,
'form'=>$form,
'model'=>$model,
'listFile'=>$listFile,
),TRUE));
$this->widget('zii.widgets.jui.CJuiTabs',array(
'tabs'=>$tabArray,
'id'=>'MyTab-Menu',
));
?>
<?php $this->endWidget(); ?>
</div>
This is the partial view _testTab1:
<table class="setup">
<?php echo '<thead><th></th><th>File Name</th><th>Load File</th><th>Delete</th></thead>' ?>
<?php foreach ($templateList as $i=>$file): ?>
<tr id="trow">
<td><?php echo CHtml::activeHiddenField($file, "[$i]id"); ?></td>
<td><?php echo 'fileID: ['.$file['id'].']'; ?></td>
<td><?php
echo CHtml::link('Reload File','#',
array('submit'=>array('setupFile','id'=>$i),
'id' => 'setup_' . $i . '_reload',
'value' => (int) $i,
'name' => 'setupFile',
));
?></td>
<td><?php
echo CHtml::link('Delete','#',
array('submit'=>array('fileDelete','id'=>$i),
'id' => 'setup_' . $i . '_delete',
'value' => (int) $i,
'name' => 'delete',
'confirm' => 'Are you sure you want to delete file '.$file['id'].'?',
));
?></td>
</tr>
<?php endforeach; ?>
</table>
This is the partial view _testTab2:
<table class="setup">
<?php echo '<thead><th></th><th>File Name</th><th>Load File</th><th>Delete</th></thead>' ?>
<?php foreach ($listFile as $i => $file): ?>
<tr id="trow">
<td><?php echo CHtml::activeHiddenField($file, "[$i]id"); ?></td>
<td><?php echo 'fileID: ['.$file['id'].']'; ?></td>
<td><?php
echo CHtml::link('Reload File','#',
array('submit'=>array('setupFileList','id'=>$i),
'id' => 'setup_' . $i . '_reload',
'value' => (int) $i,
'name' => 'setupFileList',
));
?></td>
<td><?php
echo CHtml::link('Delete','#',
array('submit'=>array('fileListDelete','id'=>$i),
'id' => 'setup_' . $i . '_delete',
'value' => (int) $i,
'name' => 'delete',
'confirm' => 'Are you sure you want to delete file '.$file['id'].'?',
));
?></td>
</tr>
<?php endforeach; ?>
</table>
On post, the File[x]['id']'s are set with the x=row number and id being the hidden field (same applies to Listfile for second tab rows). When Reload is clicked, the following action is loaded. It gets the x value (row number) and from that determines the id value. Then it loads the test/uploadFile/id page. The problem is that when I click on the Reload (or delete) link for the first three rows on the first tab, I get the id for the second tab. When I do this for the last two rows on the first tab, I get the correct id value. All links on the second tab work as expected as do each of the tabs if they are loaded individually.
public function actionSetupFile($id) {
$fileName='';
if(isset($_POST['File'])) {
if(isset($_POST['File'][(int)$id]['id'])) {
$selected = $_POST['File'][(int)$id]['id'];
$file=new File;
$fileName=$file->getFileName($selected);
$url = Yii::app()->createUrl('test/UploadFile/'.CHtml::encode((int)$selected));
}
} else {
$msg = 'Unable to complete request to upload file; try again ';
$url = Yii::app()->createUrl('test/setup');
}
$this->redirect($url, array(
'fileName'=>$fileName,
));
}
public function actionSetupFileList($id=null) {
$fileName='';
if(isset($_POST['Listfile'])) {
if(isset($_POST['Listfile'][(int)$id]['id'])) {
$selected = $_POST['Listfile'][(int)$id]['id'];
$file=new Listfile;
$fileName=$file->getFileListName($selected);
$url = Yii::app()->createUrl('test/UploadFileList/'.CHtml::encode((int)$selected));
}
} else {
$msg = 'Unable to complete request to upload file; try again ';
$url = Yii::app()->createUrl('test/setup');
}
$this->redirect($url, array(
'fileName'=>$fileName,
));
}
The post indices must be different for each tab. One way to do this is to use a multiplier for the second tab, defined as $k=100*($i+1); $i+1 because $i is 0 first and index for first row would be 0 for both tabs. Of course, some other multiplier could be used.
<table class="setup">
<?php echo '<thead><th></th><th>File Name</th><th>Load File</th><th>Delete</th></thead>' ?>
<?php foreach ($listFile as $i => $file): $k=($i+1)*100; ?>
<tr id="trow">
<td><?php echo CHtml::activeHiddenField($file, "[$k]id"); ?></td>
<td><?php echo 'fileID: ['.$file['id'].']'; ?></td>
<td><?php
echo CHtml::link('Reload File','#',
array('submit'=>array('setupFileList','id'=>$k),
'id' => 'setup_' . $k . '_reload',
'value' => (int) $k,
'name' => 'setupFileList',
));
?></td>
<td><?php
echo CHtml::link('Delete','#',
array('submit'=>array('fileListDelete','id'=>$k),
'id' => 'setup_' . $k . '_delete',
'value' => (int) $k,
'name' => 'delete',
'confirm' => 'Are you sure you want to delete file '.$file['id'].'?',
));
?></td>
</tr>
<?php endforeach; ?>
</table>
Alternatively, pass offset from view file (test5) where offset for second and subsequent tabs is count of entries in ALL prior tabs (i.e. 2nd tab: $offset=count($templateList)). Then instead of $k above, use $i + $offset):

CakePHP: Cannot determine the total working hours of employees

What I want:- I want to calculate the total working hours of my employees based on the working hours of multiple days.
My problem the total working hours ($total_hours) is not working.
My Model
class Attendence extends AppModel {
function add($data){
if (!empty($data)) {
$this->create();
if($this->save($data)) {
return true ;
}
}
}
function fetchdata() {
return $this->find('all', array('conditions' => array('Attendence.date' > '2014-04-01',
'AND' => array('Attendences.date' < '2014-04-21'),
)));
}
}
My Controller
class EmployeesController extends AppController {
public $uses = array('Employee', 'Attendence', 'InsertDate');
public function add()
{
if($this->Employee->add($this->request->data)==true){
$this->redirect(array('action'=>'index'));
}
}
public function index(){
$this->set('employees',$this->Employee->Fetch());
$this->set('attendence',$this->Attendence->fetchdata());
$this->set('dates',$this->InsertDate->fetchdate());
}
}
My View
<div class="index">
<table>
<thead>
<th>Num</th>
<th>Employee</th>
<th>Salary/Hour</th>
<th>Start Date</th>
<th>End Date</th>
<th>Total Hour</th>
<th>Total Salary</th>
</thead>
<?php
$id = 0;
foreach($employees as $e):?>
<? $id++ ?>
<tr>
<td><?php echo $e{'Employee'}{'id'} ?></td>
<td><?php echo $e['Employee']['firstname'], $e['Employee']['lastname'] ?></td>
<td style="text-align:center"><?php echo $e['Employee']['salary'] ?></td>'
<?php foreach($dates as $d):?>
<td><?php echo $d['InsertDate']['start_date'] ?></td>
<td><?php echo $d['InsertDate']['end_date'] ?></td>
<?php
$total_hours = 0;
foreach ($attendence as $et){
$ts1 = strtotime($et['Attendence']['in_time']);
$ts2 = strtotime($et['Attendence']['out_time']);
$diff = abs($ts1 - $ts2) / 3600;
$total_hours += number_format($diff,2);
}
//Total hours
echo '<td style="text-align:center">'.$total_hours.'</td>';
//Total Salary
echo '<td style="text-align:center">'.$total_hours*$e['Employee']['salary'].'</td>';
?>
<?php endforeach; ?>
<?php endforeach; ?>
</tr>
</table>
</div>
A programmer friend of mine gave me a solution. But I dont know how to implement in CAKEPHP
I am updating the solution also
Look at here :
$total_hours = 0;
foreach ($attendence as $et){
$ts1 = strtotime($et['Attendence']['in_time']);
$ts2 = strtotime($et['Attendence']['out_time']);
$diff = abs($ts1 - $ts2) / 3600;
$total_hours += number_format($diff,2);
}
The code shows you that there is an array. the array contains (attendance id and in_time and out_time in each point).
The Important thing is you should check how you fill this array.
In the above foreach that you generate the table by $employees array , you have the (employee_id) wich name (id) here
So you should write a new query in your view!!!In the middle of your first foreach and before second foreach
before this line :
$total_hours = 0
You have to write a query and fetch data from DB like this :
//SELECT * FROM attendences
WHERE attendences.date > '2014-04-23' AND attendences.date < '2014-04-30'
AND id=$e['Employee']['id'] // is your employee_id in your first array.
So when you fetched data , You have a new array named "$attendence"
Then , your second foreach(which calculates the salary and total hours) should work correctly

Time needed to load Facebook data

I'm building an analytics tool for some Facebook pages where I can view page information and statistics.
The problem is that it takes a long time to load the data using FQL, almost 50 seconds to load the page fully. The problem is that it needs to request a query for each day when I want to know all the new likes within a month and then count them all up.
These are the functions I'm using:
function getmetrics($objectid, $metrics, $end_time, $period){
global $facebook;
$fql = "SELECT value FROM insights WHERE object_id=$objectid AND metric='$metrics' AND end_time=end_time_date('$end_time') AND period=$period";
$response = $facebook->api(array(
'method' => 'fql.query',
'query' =>$fql,
));
if (!empty($response)){
return $response[0]['value'];
}
else{
return "no results found";
}
}
function getdailymetrics($objectid, $metrics, $end_time , $days ){
global $facebook;
$total = 0;
do {
$amount = getmetrics($objectid, $metrics, $end_time, '86400');
$total += $amount;
$pieces = explode("-", $end_time);
$end_time = date("Y-m-d", mktime(0, 0, 0, date($pieces[1]),date($pieces[2])-1,date($pieces[0])));
$days--;
} while($days > 1);
return $total;
}
On the front end:
<table>
<tr>
<td>Total likes</td>
<?php
$like1 = getmetrics($samsung, 'page_fans', '2012-01-29', '0');
$like2 = getmetrics($samsung, 'page_fans', '2012-02-26', '0');
$likep = round((($like2/$like1)-1)*100, 2);
?>
<td><?php echo $like1; ?></td>
<td><?php echo $likep; ?>%</td>
<td><?php echo $like2; ?></td>
</tr>
<tr>
<td>New Likes</td>
<?php
$newlikes1 = getdailymetrics($samsung, 'page_fan_adds', '2012-01-29', '28');
$newlikes2 = getdailymetrics($samsung, 'page_fan_adds', '2012-02-26', '28');
$newlikep = round((($newlikes2/$newlikes1)-1)*100, 2);
?>
<td><?php echo $newlikes1; ?></td>
<td><?php echo $newlikep; ?>%</td>
<td><?php echo $newlikes2; ?></td>
</tr>
<tr>
<td>Daily New Likes</td>
<td><?php echo round($newlikes1/28); ?></td>
<td><?php echo $newlikep; ?>%</td>
<td><?php echo round($newlikes2/28); ?></td>
</tr>
</table>
Is there a way to speed this up or is there a more efficient way?
You can try to reduce the amount of requests in two ways. First, you can use batch requests to send up to 50 queries to FB in one request. Also you can try to change your query, so that it would request insights for several days at once, like end_time in (values_list).
Also you could do some caching of the results.
And, though it depends on your certain case, maybe you could consider pulling insights with daemon (if you have the objects to pull data for), and storing it in the database.
I resolved the problem with a different method of fetching the data, using this function:
function getfromuntil($objectid, $metric, $start_time, $end_time){
global $facebook;
try {
$start_time = $timestamp = strtotime($start_time);
$end_time = $timestamp = strtotime($end_time);
$response = $facebook->api('/'.$objectid.'/insights/'.$metric.'?since='.$start_time.'&until='.$end_time);
} catch (FacebookApiException $e){
error_log($e);
}
$total = 0;
foreach ($response['data'][0]['values'] as $value) {
$total += $value['value'];
}
return $total;
}

cakephp foreach sort with titles

Hello
i'm started to learning cakephp framework.And just for start i wanted to write some simple game.
I have user controller wited already (not finished but works :D) and now i started to write equipment. But i stuck at the moment i'm trying to sort foreach by type (helmet, armor, shield etc) and now script output table like this:
Id Owner Name Status Type Cost
1 23 Krasnoludzka Salada B H 100
2 23 Jakieś spodnie B L 10
3 23 Zbroja B A 123
But i wanna to make it like this:
Id Owner Name Status Type Cost
Helmets:
1 23 Krasnoludzka Salada B H 100
4 23 Smocza Salada B H 100
Legs:
2 23 Jakieś spodnie B L 10
Armors:
3 23 Zbroja B A 123
Mine equipments_controller.php:
<?php
class EquipmentsController extends AppController {
var $name = 'Equipments';
var $helpers = array('Html', 'Form');
function index() {
$this->set('equipments', $this->Equipment->find('all', array('conditions' => array('owner='.$this->Session->read('Auth.User.id'), 'status=\'B\''))));
//$this->set('equipments', $this->Equipment->find('owner='.$this->Session->read('Auth.User.id')));
}
function view ($id = null) {
$this->Equipment->id = $id;
$owner = $this->Equipment->read('owner');
if ($owner['Equipment']['owner']==$this->Session->read('Auth.User.id')) {
$this->redirect(array('controller' => 'equipments', 'action' => 'index'));
$this->Session->setFlash('To nie twój przedmiot!');
} else {
$this->set('equipment', $this->Equipment->read());
}
}
}
And equipments/index.ctp:
<!-- File: /app/views/news/index.ctp (edit links added) -->
<h1>Plecak</h1>
<table>
<tr>
<th>Id</th>
<th>Owner</th>
<th>Name</th>
<th>Status</th>
<th>Type</th>
<th>Cost</th>
</tr>
<!-- Here's where we loop through our $news array, printing out news info -->
<?php foreach ($equipments as $equipment): ?>
<tr>
<td><?php echo $equipment['Equipment']['id']; ?></td>
<td><?php echo $equipment['Equipment']['owner']; ?></td>
<td><?php echo $equipment['Equipment']['name']; ?></td>
<td><?php echo $equipment['Equipment']['status'];?></td>
<td><?php echo $equipment['Equipment']['type']; ?></td>
<td><?php echo $equipment['Equipment']['cost']; ?></td>
</tr>
<?php endforeach; ?>
</table>
Can anyone help me?
You can add a 'group' option to your find()...
$this->set(
'equipments',
$this->Equipment->find(
'all',
array(
'conditions' => array(
'Equipment.owner' => $this->Session->read('Auth.User.id'),
'Equipment.status' => 'B'
),
'group' => array(
'Equipment.type'
),
'order' => array(
'Equipment.type',
'Equipment.name',
),
)
)
);
Hopefully you've actually got a Model for those types, and can use that model instead of those Equipment.type values, something like EquipmentType.name would be useful in your view. If you had that, then you'd be able to output a new heading row each time the EquipmentType.id changed.
I I'm understanding you correctly, you'd like to be able to sort your table of data by the titles in the table head tags.
If this is the case, I'd suggest using cake's built in paginator.
Your controller should look like:
class EquipmentsController extends AppController {
var $name = 'Equipments';
var $helpers = array('Html', 'Form');
public $paginate = array(
'Equipment' => array(
'limit' => 25,
'order' => array(
'Equipment.id' => 'ASC'
)
)
);
function index() {
$owner = $this->Session->read('Auth.User.id');
$equipments = $this->paginate('Equipment', array(
'Equipment.owner' => $owner,
'Equipment.status' => 'B'
));
$this->set(compact('equipments'));
}
}
Then in your views/equipments/index.ctp:
<!-- File: /app/views/news/index.ctp (edit links added) -->
<h1>Plecak</h1>
<table>
<tr>
<th><?=$this->Paginator->sort('Id', 'Equipment.id')?></th>
<th><?=$this->Paginator->sort('Owner', 'Equipment.owner')?></th>
<th><?=$this->Paginator->sort('Name', 'Equipment.name')?></th>
<th><?=$this->Paginator->sort('Status', 'Equipment.status')?></th>
<th><?=$this->Paginator->sort('Type', 'Equipment.type')?></th>
<th><?=$this->Paginator->sort('Cost', 'Equipment.cost')?></th>
</tr>
<!-- Here's where we loop through our $news array, printing out news info -->
<?php foreach ($equipments as $equipment): ?>
<tr>
<td><?php echo $equipment['Equipment']['id']; ?></td>
<td><?php echo $equipment['Equipment']['owner']; ?></td>
<td><?php echo $equipment['Equipment']['name']; ?></td>
<td><?php echo $equipment['Equipment']['status'];?></td>
<td><?php echo $equipment['Equipment']['type']; ?></td>
<td><?php echo $equipment['Equipment']['cost']; ?></td>
</tr>
<?php endforeach; ?>
Using the paginator this way will generate links in your table headers that will automatically sort the data coming out of the db.

Categories