dongtaigan1594 2016-05-05 14:06
浏览 141
已采纳

从视图中的php变量中获取值

I have a form where I have multiple upload buttons. Banner, Cover and HeadlinerX, the X is replaced by a number 1,2...X This means I can have multiple buttons for upload headliners.

I have this hidden input (in my view) where I store the amount of headliners.

<input type="hidden" name="qtd_headliners" id="qtd_headliners" value="<?php echo $qtd_headliners?>" />

I tried this way (method in controller) to access it but it doesn't do anything it only adds banner and cover.

public function uploadOptions(){

    $opt = array();

    for ($i=1; $i <= $_POST['qtd_headliners']; $i++) { 
        if(!array_key_exists($i, $_POST))
            continue;

        $headliner = $_POST('headliners'.$i);
        $opt[$i] = $headliner;
        $this->set('Headliner' . $opt[$i] , 'debug');
    }

    array_push($opt, 'banner', 'cover');

    return $opt;
}

Can anyone point me in the right direction?

  • 写回答

2条回答 默认 最新

  • duanfaxin7014 2016-05-05 14:37
    关注

    After a couple of minutes re-reading the code I found my error and solution.

    public function uploadOptions(){
        $opt = array();
        array_push($opt, 'banner', 'cover');
    
        for ($i=1; $i <= $_POST['qtd_headliners']; $i++) { 
            $headliner = 'headliner'.$i;
            array_push($opt, $headliner);
        }
    
        return $opt;
    }
    

    Thanks anyway @Cili and @arilia

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题