开发者

CakePHP find('neighbors') use [next] and [prev] from array

开发者 https://www.devze.com 2023-01-14 13:27 出处:网络
I am trying to get the neighbors Ids of the current Id. What I have below works, but I cannot separate the [prev] from the [next] link.

I am trying to get the neighbors Ids of the current Id. What I have below works, but I cannot separate the [prev] from the [next] link. The function in the controller looks as follows:

function prevNext() {
    return $this->System->find('neighbors', array('fields' => 'name', 'value' => 3));
 }

Which will output something like this:

Array
(
    [prev] => Array
        (
            [System] => Array
                (
                    [name] => Aegerter
                    [id] => 4004
                )

        )

    [next] => Array
        (
            [System] => Array
                (
                    [name] => Canonica
                    [id] => 4006
                )

        )

)

This gets passed as a requestAction -

<?php $systems = $this->requestAction('systems/prevNext'); ?>
 <?php foreach($sys开发者_如何学编程tems as $system): ?>
  <?php echo $html->link($system['System']['id'],array('action'=>'view', $system['System']['id']));?>, <?php echo  $system['System']['name'];?>
 <?php endforeach; ?>

into the view as an element:

<?php echo $this->element('systems'); ?>

How do you call the [prev] and [next] link separately (not a foreach output)? Tia


If i understand correctly:

<?php echo $html->link($systems['prev']['System']['id'],array('action'=>'view', $systems['prev']['System']['id']));?>, <?php echo  $systems['next']['System']['name'];?>

<?php echo $html->link($systems['next']['System']['id'],array('action'=>'view', $systems['next']['System']['id']));?>, <?php echo  $systems['next']['System']['name'];?>
0

精彩评论

暂无评论...
验证码 换一张
取 消