首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >CakePHP -将多个值从视图元素传递到控制器

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

Stack Overflow用户
提问于 2015-06-15 02:04:40
回答 1查看 332关注 0票数 1

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

实际上,我使用的是以下代码:

 <?
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
    }

有谁能帮我得到第二个值吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-17 03:30:10

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

// 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30832763

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档