控制器代码:
$this->loadModel('Social');
$this->set('social', $this->Social->find('all',array('fields'=>array('Social.id','Social.semfieldvalue'))));
查看代码:
<?php foreach ($social as $socials): ?>
<td><?php echo $socials['Social']['semfieldvalue']; ?></td>
<?php endforeach; ?>
现在我获得了半场列的所有字段值。
但是现在在我的视图文件中我要打印。不同位置的第1行值和差异处的第2行值。所以如何在cakephp中执行此操作。
我在<?print_r($social); ?>
Array ( [0] => Array ( [Social] => Array ( [id] => 1 [semfieldvalue] => http://www.facebook.com/new ) ) [1] => Array ( [Social] => Array ( [id] => 2 [semfieldvalue] => http://www.twitter.com/new ) ) [2] => Array ( [Social] => Array ( [id] => 3 [semfieldvalue] => http://www.linkedin.com/new ) ) [3] => Array ( [Social] => Array ( [id] => 4 [semfieldvalue] => http://www.google.com/new ) ) ) http://www.facebook.com/new
所以我得到了所有的价值但我想在差异处打印id 1并在同一视图文件中的差异处打印id
答案 0 :(得分:2)
在Array中打印第一个值:使用
echo $social[0]['Social']['semfieldvalue'];
打印第二个val
echo $social[1]['Social']['semfieldvalue'];