[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Help finding how the page is being sorted?!?

Posted on 2016-09-14
6
Medium Priority
?
114 Views
Last Modified: 2016-10-19
Hi Experts,

I have a php application that lists all the student members on a form.  

Where is the sort being set?

I have a file super_index_students.ctp that lists all the member students in the system.  I can see that a sort is set in the headers and it works, but we would like it to be desc by default and able to switch back and forth.  I should be able to edit line 23 to reflect below, but it doesn't work.  The sort is still ASC.  So where is the sort coming from?

I understand when a cakephp app is created the View pulls the data from the Controller.  I do see a function included in the Member controller called the same name, but I can't find any sort there either.   What am I missing or doing wrong?  Any suggestions would be greatly appreciated.

Example of the desc order I want.
<th><?php echo $paginator->sort('id',null,array('direction'=>'desc'));?></th>

Open in new window


member_controller
function super_index_students() {

        $this->admincheck();

        $this->set('security_id', $this->Session->read('security_id'));

        $this->Member->recursive = -1;

        $students = $this->paginate('Member', array('member_type_id'=>1));

        $this->set('members', $students);

    }

Open in new window


super_index_students.ctp
<br /><br /><br /><?php //var_dump($members); 
//var_dump($students_array); ?>
<?php 
	echo $form->create(array('method'=>'link', 'action' => 'search_students', 'controller'=>'members','super'=>true));
    echo $form->end(array('label'=>'Search')); 
	// echo $html->link(__('Search', true), array('controller'=> 'members', 'action'=>'search_students'));  

?>
<div class="members index">
<h1 class="heading"><?php __('Students Index');?></h1>
<p>
<?php
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
));
?></p>
<p align="right" style="font-weight:bold;color:#ea8f40;margin-bottom:0px;padding-right:15px;">
A=Assign | E=Edit | D=Delete
</p>
<table cellpadding="5" cellspacing="0" class="admin_table">
<tr>
           
	<th><?php echo $paginator->sort('id');?></th>

	<th><?php echo $paginator->sort('username');?></th>

	<th>Name(<?php echo $paginator->sort('first');?> 
	 <?php echo $paginator->sort('last');?>)</th>
	<th><?php echo $paginator->sort('email');?></th>
	<th><?php echo $paginator->sort('phone');?></th>
	<th><?php echo $paginator->sort('active');?></th>
	<th class="actions" style="width:50px" align=left><?php __('Actions');?></th>
</tr>
<?php
$i = 0;

foreach ($members as $member):
	$class = null;
	if ($i++ % 2 == 0) {
		$class = ' class="altrow"';
	}
?>
	<tr<?php echo $class;?>>
		<td>
			<?php echo $member['Member']['id']; ?>
		</td>
		<td>
			<?php echo $member['Member']['username']; ?>
		</td>
		<td>
			<?php echo $member['Member']['first']; ?> <?php echo $member['Member']['last']; ?>
		</td>
		<td>
			<?php echo $member['Member']['email']; ?>
		</td>
		<td>
			<?php echo $member['Member']['phone']; ?>
		</td>
		<td>
			<?php echo $member['Member']['active']; ?>
		</td>
		<td class="actions" style="width:50px" align=left>

            <?php
            if(empty($member['StudentsAndTutor'])){
                echo $html->link(__('A', true), array('controller'=> 'students_and_tutors', 'action'=>'student_assign', $member['Member']['id']));
            } ?> | 
            <?php //echo $html->link(__('View', true), array('action'=>'view', $member['Member']['id'])); ?>
			<?php echo $html->link(__('E', true), array('action'=>'edit_student', $member['Member']['id'])); ?>
			 | 
			<?php echo $html->link(__('D', true), array('action'=>'delete', $member['Member']['id'],1, '?sid=' . $security_id), null, sprintf(__('Are you sure you want to delete # %s?', true), $member['Member']['id'],1)); ?>
		</td>
	</tr>
<?php endforeach; ?>
</table>
</div>
<?php //pr($members); ?>
<div class="paging" style="padding-left:15px; padding-top:15px;" align="left">
	<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
 | 	<?php echo $paginator->numbers();?>
	<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?>
</div>
<!--
<div class="actions">
	<ul>
        <li><?php echo $html->link(__('List Tutors', true), array('action'=>'index_tutors')); ?></li>
        <li><?php echo $html->link(__('Back to Admin', true), array('action'=>'index')); ?></li>
 
		<li><?php echo $html->link(__('New Member', true), array('action'=>'add')); ?></li>
		<li><?php echo $html->link(__('List Member Types', true), array('controller'=> 'member_types', 'action'=>'index')); ?> </li>
		<li><?php echo $html->link(__('New Member Type', true), array('controller'=> 'member_types', 'action'=>'add')); ?> </li>
		<li><?php echo $html->link(__('List Languages Members', true), array('controller'=> 'languages_members', 'action'=>'index')); ?> </li>
		<li><?php echo $html->link(__('New Languages Member', true), array('controller'=> 'languages_members', 'action'=>'add')); ?> </li>
		<li><?php echo $html->link(__('List Students And Tutors', true), array('controller'=> 'students_and_tutors', 'action'=>'index')); ?> </li>
		<li><?php echo $html->link(__('New Students And Tutor', true), array('controller'=> 'students_and_tutors', 'action'=>'add')); ?> </li>
		<li><?php echo $html->link(__('List Tutor Lessons', true), array('controller'=> 'tutor_lessons', 'action'=>'index')); ?> </li>
		<li><?php echo $html->link(__('New Tutor Lesson', true), array('controller'=> 'tutor_lessons', 'action'=>'add')); ?> </li>

    </ul>
</div>
-->

<div class="actions" style="width:100%">
<table border="0" style="width:100%;margin:0 auto;"><tr><td align="right"> 
<?php

	echo $form->create(array('method'=>'link', 'action' => 'index_tutors', 'controller'=>'members','super'=>true));
    echo $form->end(array('label'=>'Tutor Index','div'=>'')); 
	echo '</td><td align="left">';	
	echo $form->create(array('method'=>'link', 'action' => 'index', 'controller'=>'members','super'=>true));
    echo $form->end(array('label'=>'Admin Home','div'=>'')); 
?>
</td></tr> </table>
</div>
<br><br> 

Open in new window

0
Comment
Question by:rcowen00
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 41798851
Change
<th><?php echo $paginator->sort('username');?></th>

to
<th><?php echo $paginator->rsort('username');?></th>

For additional references on PHP sorting methods, I refer you here.
0
 

Author Comment

by:rcowen00
ID: 41798993
When I changed that the header disappeared and the  order is still ASC.
0
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 41799104
okay -  change the sort on line 25 to rsort.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 41799105
Which PHP implementation and version are you using?
0
 

Author Comment

by:rcowen00
ID: 41810043
PHP Version      5.2.17
0
 
LVL 15

Accepted Solution

by:
WalkaboutTigger earned 2000 total points
ID: 41819341
Just to be clear, you want the default sort to be descending as opposed to ascending.

In the Member_Controller can you try changing line 9:
$students = $this->paginate('Member', array('member_type_id'=>1) DESC');

Open in new window

0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question