簡體   English   中英

將變量從視圖傳遞到控制器

[英]passing variables from views to controllers

我將盡力解釋這一點。 我從控制器返回了一系列結果。 我希望將所選行的主鍵發送給另一個控制器,該控制器將在用戶單擊“添加員工”按鈕時管理將記錄插入數據庫中。 我的主鍵是MOVIE_ID 像這樣{12341, 31351}當前正在返回兩個MOVIE_ID {12341, 31351}的數組。 我的問題是:

  1. 如何將每個電影ID與相應行的按鈕唯一關聯?

  2. 我可以通過action=""屬性將變量傳遞給控制器​​嗎,我需要JS嗎?

在此處輸入圖片說明

            <fieldset id= "results">

                <?php if (isset($results ) And count($results)) : ?>
                    <table id="box-table-a" summary="Employee Sheet">
    <thead>
        <tr>
            <th scope="col">Employee</th>
            <th scope="col">Salary</th>
            <th scope="col">Bonus</th>
            <th scope="col">Supervisor</th>
            <th scope="col">Action</th>
        </tr>


            <?php foreach ($results as $result) : ?>
                            <tr>
//Primary key <?php echo $result['MOVIE_ID!'];?>
<td><span class="Employee_name"><?php echo $result['Employee']; ?> </span></td>         
<td><span class="Salary"><?php echo $result['Salary']; ?> </span> </td>
<td><span class="Bonus"><?php echo $result['Bonus']; ?> </span> </td>
<td><span class="Supervisor_name"><?php echo $result['Supervisor']; ?> </span></td>
<td><input type="submit" value="add employee" > </td>

    </tr>

    <?php endforeach; ?>
        <?php endif; ?>
    </thead>
        <tbody>
    </fieldset>

一種技巧是通過提交按鈕傳遞id,如下所示:

<input name="submit[12341]" type="submit" value="add employee" />

單擊后,它將在POST數據中發送submit[12341]=add+employee (假設您已將所有內容包裝在<form>標記內)。 其他按鈕將不會提交,只有單擊的按鈕會提交。

在PHP中,您可以像這樣檢索ID:

$id = key($_POST['submit']);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM