cakephp,点击链接时如何将值传递给会话?

时间:2015-01-24 05:05:16

标签: cakephp cakephp-2.3

我的项目中有四个分支,当我点击branch1时,会话应该存储branch1,同样的方式分支2,3 ......

<?php foreach($val as $value) {?>

<tr>
<th><span><?php echo $this->Html->link($value['Branch']['branch_name'], array('controller' => 'branchs', 'action' => 'index','onclick'=> 'update')) ?></span></th>
<?php  CakeSession::write('sa',$value['Branch']['branch_name']); ?>
</tr>
<?php } ?>
<tr>

1 个答案:

答案 0 :(得分:1)

<?php foreach($val as $value) {?>
<tr>
  <th><span>
  <?php echo $this->Html->link($value['Branch']['branch_name'],array('controller' => 'branchs', 'action' => 'index','onclick'=> 'update')) ?></span>
</th>
<?php  $this->Session->write('sa',$value['Branch']['branch_name']; ?>
 </tr>
<?php } ?>

  

我的演示代码

$val=array('1','3','4');
        foreach ($val as $key => $value) {
            $this->Session->write('sa',$val);
        }
        $val1=$this->Session->read('sa');
        foreach ($val1 as $key => $value) {
            echo $value.'<br>';
        }
  

我的演示输出   enter image description here