Jump to content

Recommended Posts

Hello,

 

 

I am creating a simple catalog feature on my website for logging collections in a list format.

 

Using built in pagination (cakephp) on my list to sort by name, I lose my images after the sort. Any ideas how to get around this?

 

Here is the code.

 

View:

<td><div align='center'>
            <?php echo $this->Html->toggleBoolean($nintendo['Nintendo']['box']); ?>
        </div></td>

 

Helper:

    function toggleBoolean($value){
        if ($value == 1)
            return "<img src='../img/fam/tick.png' alt='Yes' />";
        else
            return "<img src='../img/fam/cross.png' alt='No' />";
    }

Regards,

Ash

Link to comment
https://forums.phpfreaks.com/topic/248112-losing-images-after-pagination-sort/
Share on other sites

$this is reserved for use inside classes. I don't see the whole script that that snippet was a part of, but seeing you use $this when you have HTML near its use tells me you may be using $this incorrectly. Are there any errors on the page? Can you post more of the code surrounding that snippet?

Thanks for the reply mikesta707. Here is the full index for one of my catalog items, the controller, and the helper. Let me know if you need any more information.

 

 

view -> index:

<?php
echo $this->Html->image('../img/nintendo_logo.jpg', array('alt' => 'nintendo'));
?>
<br /><br />
<?php
if($this->Session->read('Auth.User.admin')){
	echo $html->link($html->image("../img/fam/add.png", array('alt' => 'add', 'style' => 'padding-top:3px')), array('action' => 'add'), array('escape' => false));
};
echo " ";
?>
<?php
if($this->Session->read('Auth.User.admin')){
echo $html->link('Add Game',array('controller' => 'nintendos', 'action' => 'add'));
}
?>
<table>
<tr>
		<th><?php echo $this->Paginator->sort('Name', 'Nintendo.name');?></th>
		<th><div align='center'><?php echo $this->Paginator->sort('Type', 'Nintendo.type');?></div></th>
		<th><div align='center'><?php echo $this->Paginator->sort('Release', 'Nintendo.release');?></div></th>
		<th><div align='center'>Box</div></th>
		<th><div align='center'>Manual</div></th>
<?php
if($this->Session->read('Auth.User.admin')){ echo "<th><div align='center'>Action</div></th>";}
?>
</tr>
<?php foreach ($nintendos as $nintendo): ?>
<tr>
	<td>
		<?php echo $nintendo['Nintendo']['name']; ?>
	</td>
	<td><div align='center'>
		<?php echo $nintendo['Nintendo']['type']; ?>
	</div></td>
	<td><div align='center'>
		<?php echo $nintendo['Nintendo']['release']; ?>
	</div></td>
	<td><div align='center'>
		<?php echo $this->Html->toggleBoolean($nintendo['Nintendo']['box']); ?>
	</div></td>
	<td><div align='center'>
		<?php echo $this->Html->toggleBoolean($nintendo['Nintendo']['manual']); ?>
	</div></td>
	<?php
				if($this->Session->read('Auth.User.admin')){
				  echo "<td><div align='center'>";
		  echo $html->image("../img/fam/bin_closed.png", array("alt" => "delete",'url' => array('controller' => 'nintendos', 'action' => 'delete',
			$nintendo['Nintendo']['id']),"onclick" => "return confirm(\"Are you sure?\")")); echo "  ";
		  echo $html->image("../img/fam/pencil.png", array("alt" => "edit",'url' => array('controller' => 'nintendos', 'action' => 'edit',
			$nintendo['Nintendo']['id']))); 
		   echo "</div></td>";}
			   endforeach;?>
</table>

 

Controller

<?php
class NintendosController extends AppController {
    var $name = 'Nintendos';
            var $paginate = array(
                'limit' => 99999,
                'order' => array(
                'Nintendo.name' => 'asc')
            );
            
    function index() {
	$this->set('nintendos', $this->paginate());
            }
    
            function add() {
	if (!empty($this->data)) {
	    if ($this->Nintendo->save($this->data)) {
		$this->Session->setFlash('Your game has been saved.');
		$this->redirect(array('action' => 'index'));
	    }
	}
    }
    
            function delete($id) {
	if ($this->Nintendo->delete($id)) {
	    $this->Session->setFlash('The game with id: ' . $id . ' has been deleted.');
	    $this->redirect(array('action' => 'index'));
	}
    }
    
            function edit($id = null) {
	$this->Nintendo->id = $id;
	if (empty($this->data)) {
	    $this->data = $this->Nintendo->read();
	    }else{
                        if ($this->Nintendo->save($this->data)) {
		    $this->Session->setFlash('Your game has been updated.');
		    $this->redirect(array('action' => 'index'));
	    }
                }
            }
        }
?>

 

Helper

<?php

App::import('View', 'Helper', false);

class AppHelper extends Helper {
function toggleBoolean($value){
	if ($value == 1)
		return "<img src='../img/fam/tick.png' alt='Yes' />";
	else
		return "<img src='../img/fam/cross.png' alt='No' />";
}
}
?>

[/code]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.