在Codeigniter中获取数组到控制器的值

时间:2016-08-24 14:04:43

标签: php arrays codeigniter

我在视图中有代码

Option Explicit
Public Sub RunMe()
    Const AFTARTKRZ_COL As Long = 4
    Const VTR_COL As Long = 6
    Dim data As Variant
    Dim GAPs As Collection
    Dim RSVs As Collection
    Dim multis As Collection
    Dim vtrKey As String
    Dim multi(0 To 1) As Long
    Dim i As Long, r As Long, c As Long
    Dim v As Variant
    Dim countRSV As Long
    Dim output() As Variant

    'Name your sheets.
    'If you have fewer than 3 sheets or
    'sheets already names A, B, C then this
    'will throw an error.
    Sheet1.Name = "A"
    Sheet2.Name = "B"
    Sheet3.Name = "C"

    'Initialise the 3 collections
    Set GAPs = New Collection
    Set RSVs = New Collection
    Set multis = New Collection

    'Read the data - I've put my dummy data on Sheet4
    data = Sheet4.UsedRange.Value2
    'Iterate rows and place row in relevant collection
    For r = 1 To UBound(data, 1)
        vtrKey = CStr(data(r, VTR_COL))
        On Error Resume Next 'removes duplicate entries
        Select Case data(r, AFTARTKRZ_COL)
            Case Is = "GAPNK", "GAPN2": GAPs.Add r, vtrKey
            Case Is = "RSLNV": RSVs.Add r, vtrKey & "|RSLNV"
            Case Is = "RSVNK": RSVs.Add r, vtrKey & "|RSVNK"
        End Select
        On Error GoTo 0
    Next

    'Check if each GAP also has RSVs
    For Each v In GAPs
        vtrKey = CStr(data(v, VTR_COL))
        countRSV = 0
        If Exists(RSVs, vtrKey & "|RSLNV") Then countRSV = countRSV + 1
        If Exists(RSVs, vtrKey & "|RSVNK") Then countRSV = countRSV + 2
        If countRSV > 0 Then
            multi(0) = CLng(v)
            multi(1) = countRSV
            multis.Add multi, vtrKey
        End If
    Next

    'Write your outputs
    'Sheet C
    ReDim output(1 To RSVs.Count + 1, 1 To UBound(data, 2))
    For c = 1 To UBound(data, 2)
        output(1, c) = data(1, c)
    Next
    i = 2
    For Each v In RSVs
        For c = 1 To UBound(data, 2)
            output(i, c) = data(v, c)
        Next
        i = i + 1
    Next

    With Sheet3
        .Cells.Clear
        .Range("A1").Resize(UBound(output, 1), UBound(output, 2)).Value = output
        .Columns.AutoFit
    End With

    'Sheet B
    ReDim output(1 To GAPs.Count + 1, 1 To UBound(data, 2))
    For c = 1 To UBound(data, 2)
        output(1, c) = data(1, c)
    Next
    i = 2
    For Each v In GAPs
        For c = 1 To UBound(data, 2)
            output(i, c) = data(v, c)
        Next
        i = i + 1
    Next

    With Sheet2
        .Cells.Clear
        .Range("A1").Resize(UBound(output, 1), UBound(output, 2)).Value = output
        .Columns.AutoFit
    End With

    'Sheet A
    ReDim output(1 To multis.Count + 1, 1 To 5)
    output(1, 1) = "VTR"
    output(1, 2) = "AFTARTKRZ"
    output(1, 3) = "Add1"
    output(1, 4) = "Add2"
    i = 2
    For Each v In multis
        r = v(0)
        output(i, 1) = data(r, VTR_COL)
        output(i, 2) = data(r, AFTARTKRZ_COL)
        output(i, 2) = data(r, AFTARTKRZ_COL)
        Select Case v(1)
            Case 1
                output(i, 3) = "RSLNV"
                output(i, 5) = "Appeared twice as (GAPNK or GAPN2), RSLNV"
            Case 2
                output(i, 3) = "RSVNK"
                output(i, 5) = "Appeared twice as (GAPNK or GAPN2), RSVNK"
            Case 3
                output(i, 3) = "RSLNV"
                output(i, 4) = "RSVNK"
                output(i, 5) = "VTR appeared thrice"
        End Select
        i = i + 1
    Next

    With Sheet1
        .Cells.Clear
        .Range("A1").Resize(UBound(output, 1), UBound(output, 2)).Value = output
        .Columns.AutoFit
    End With

End Sub
Private Function Exists(col As Collection, key As String) As Boolean
    Dim v As Variant

    On Error Resume Next
    v = col(key)
    On Error GoTo 0
    Exists = Not IsEmpty(v)

End Function
控制器中的

  $(container).append('<div class="form-group">'+'<input type=text name="situs[]" class="input" id=tb' + iCnt + ' ' +
                        'placeholder="www.namasitus.com"' + iCnt + '" />');

我只得到1个值(数组中的最后一个值) 如何解决这个问题

1 个答案:

答案 0 :(得分:1)

每次都要覆盖$ dataa变量。

if (isset($_POST['situs']))
{
    $dataa = [];
    $array_domain = $_POST['situs'];
    foreach ($array_domain as $value) // loop array
    {
        $dataa[] = ['situs' => $value];
    }
}

试试这个。