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 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程