CakePHP - 将多个值从视图元素传递到控制器

时间:2015-06-14 18:04:40

标签: php cakephp

我想从视图中将一些值传递给我的控制器。

其实我正在使用以下代码:

 <?
echo $this->element('produtos-categoria', array(
    'categoria_id' => $produtos['Produto']['categoriasproduto_id'],
    'produto_id' => $produtos['Produto']['id']
));
?>

但是我无法在控制器中获得第二个值,只是第一个值即将到来:

public function list_categories($categoria_id = null, $produto_id = null ) {
        pr($produto_id); exit; //empty
    }

任何人都可以帮助他获得第二个价值吗?

1 个答案:

答案 0 :(得分:1)

我不知道你想要实现什么,但要获得第二个变量,你需要将第二个参数设置为你的方法。

// If you want to set variable from a function and get it from an other function
public function an_other_function(){
    $this->listacategorias(22, 333);
}

public function listacategorias($categoria_id = null, $produto_id = null ) {
    var_dump($categoria_id);
    var_dump($produto_id);
}


// If you want to set and get variable from url
host_or_domain_name/controller_name/listacategorias/22/33